Question

In: Computer Science

In C 1- Use nested for loops to create an addition lookup table. Fill in an...

In C

1- Use nested for loops to create an addition lookup table. Fill in an array and print out the following table showing the sum of the row and column numbers 0-9.

0  1  2  3  4..   <- column numbers   
1  2  3  4  5..   
2  3  4  5  6..  <- These nos. = Row + Column   
3  4  5  6  7..  <- for example 7 = 3 + 4   
4  5  6  7  8.. 
...   
^Row numbers

2- use

A hexadecimal version 16x16 table 0-F. Use print specifier %x to print numbers in hex instead of decimal.

Solutions

Expert Solution

(1)

C Program:

/* C Program that prints addition look up table */

#include <stdio.h>
#include <stdlib.h>

//Main program
int main()
{
    int i,j;

    printf("\n");

    //Printing starting row (Row number)
    for(i=0; i<=9; i++)
    {
        //Printing row number
        printf(" %-4d ", i);
    }

    //Iterating over remaining rows
    for(i=1; i<=9; i++)
    {
        //Printing row number
        printf("\n %-4d ", i);

        //Iterating over columns
        for(j=1; j<=9; j++)
        {
            //Printing column values
            printf(" %-4d ", (i+j));
        }
    }

    printf("\n\n");
    return 0;
}

--------------------------------------------------------------------------------------------------------------------------------------------------------------------

Sample Output:

_____________________________________________________________________________________________

(2)

/* C Program that prints hexadecimal numbers */

#include <stdio.h>
#include <stdlib.h>

//Main program
int main()
{
    int i, j;

    printf("\n %4c ", '+');

    //Printing starting row
    for (i = 0; i < 16; i++)
    {
        //Printing row
        printf(" %4X ", i);
    }

    //Printing decimal and equivalent hexadecimal numbers

    //Printing rows
    for (i=0; i<16; i++)
    {
        //Printing row
        printf("\n %4X ", i);

        for(j=0; j<16; j++)
        {
            //Printing value
            printf(" %4X ", (i+j));
        }
    }

    printf("\n\n");
    return 0;
}

Sample Output:


Related Solutions

Can you create a player vs computer Hangman game on MATLAB using nested loops, for loops,...
Can you create a player vs computer Hangman game on MATLAB using nested loops, for loops, if loops, while loops, arrays and conditional execution, as well as creating an image of the game board. The list below must be considered in the code. - Selecting a word from a dictionary (a text file) - Reading a single letter from the user - Building a character array showing the letters matched so far - Keeping count of the number of guessed...
C++ In this lab you will be using nested for loops to print out stars in...
C++ In this lab you will be using nested for loops to print out stars in a Diamond pattern such as this: * *** ***** ******* ********* *********** ************* *************** ************* *********** ********* ******* ***** *** * For example , if number of rows=8 then the above pattern is derived. You are to take the input for the number of lines(rows) from a file named "input_diamond" and output the pattern into both the terminal and an output file named "output_diamond".
Write a Java program that uses nested for loops to print a multiplication table as shown...
Write a Java program that uses nested for loops to print a multiplication table as shown below.   Make sure to include the table headings and separators as shown.   The values in the body of the table should be computed using the values in the heading   e.g. row 1 column 3 is 1 times 3.
IN C++ Write a program that uses nested loops to collect data and calculate the average...
IN C++ Write a program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask the user for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the ­­program should display the...
Write a C++ program that uses nested loops to collect data and calculate the average rainfall...
Write a C++ program that uses nested loops to collect data and calculate the average rainfall over a period of years. The program should first ask the user for the number of years. The outer loop will iterate once for each year. The inner loop will iterate 12 times, once for each month. Each iteration of the inner loop will ask the user for the inches of rainfall for that month. After all iterations, the program should display the number...
create a function in matlab that sums two m x n matrices using nested loops, then...
create a function in matlab that sums two m x n matrices using nested loops, then returns result into a new matrix. Use nesed for loops to add matrices piece by piece. Basically means, dont program simply A+B Function should perform error check to make sure both matrices have same number of rows/ columns.
MATLAB is program Respond fast please a quiz Create a MATLAB script. Using nested for loops,...
MATLAB is program Respond fast please a quiz Create a MATLAB script. Using nested for loops, evaluate the multivariable function: z = sin ⁡ ( x ) cos ⁡ ( y ) for x between -4 and 4 in steps of 1 y between -2 and 2 in steps of 1 Display the matrix z Cut and paste the following into a word doc and submit to this question. Your script code Your input Your output
Create a random matrix of size 10x10, of integers between 1 and 1000, and use nested...
Create a random matrix of size 10x10, of integers between 1 and 1000, and use nested for loops over the elements of the matrix to find the number of prime elements , as well as the sum of the prime elements in the matrix. You can use MATLAB's built-in function isprime to check if an element is a prime number. You should have these variable: cnt (counts the number of prime elements) sm (sum of prime elements) In the command...
1.) Explain how to calculate the amount financed, financecharge, and APR by table lookup. Do...
1.) Explain how to calculate the amount financed, finance charge, and APR by table lookup. Do you think the Truth in Lending Act should regulate interest charges?  
C++ Language Implement a two-dimensional image using a nested loop. 1) Create an integer constant DIM...
C++ Language Implement a two-dimensional image using a nested loop. 1) Create an integer constant DIM and set it equal to 5. 2) Use a nested loop to print the output in terms of DIM. Example output: ***** *---* *---* *---* *****
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT