Question

Create a square array and fill out as shown below. Use nested loop for this step....

Create a square array and fill out as shown below. Use nested loop for this step. 1 3 5 7 9 2 4 6 8 10 3 5 7 9 11 4 6 8 10 12 5 7 9 11 13 Then create two 1D arrays to with row and column sum of the items. You have then 15 25 35 45 55 for the column sum, and 25 30 35 40 45 for the row sum. Print row and column sum arrays on screen.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Code

#include<iostream>

using namespace std;

int main()
{
   int size=5;
   int arr[5][5];
   int row[5], col[5];
   int val;
   for (int i = 0; i < size; i++)
   {
       val = i + 1;
       for (int j = 0; j < size; j++)
       {
           arr[i][j] = val;
           val += 2;
       }
   }
   //row sum
   for (int i = 0; i < size; i++)
   {
       int sum = 0;
       for (int j = 0; j < size; j++)
           sum += arr[i][j];
       row[i] = sum;
   }
   //col sum
   for (int i = 0; i < size; i++)
   {
       int sum = 0;
       for (int j = 0; j < size; j++)
           sum += arr[j][i];
       col[i] = sum;
   }
   cout << "Row sum: ";
   for (int i = 0; i < 5; i++)
       cout << row[i] << " ";

   cout << "\n\nCol sum: ";
   for (int i = 0; i < 5; i++)
       cout << col[i] << " ";
   cout << endl << endl;
   system("pause");
   return 0;
}

output

If you have any query regarding the code please ask me in the comment i am here for help you. Please do not direct thumbs down just ask if you have any query. And if you like my work then please appreciates with up vote. Thank You.

Add a comment
Know the answer?
Add Answer to:
Create a square array and fill out as shown below. Use nested loop for this step....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Create a square array and fill out as shown below. Use a nested loop for this...

    Create a square array and fill out as shown below. Use a nested loop for this step. 1 3 5 7 9 2 4 6 8 10 3 5 7 9 11 4 6 8 10 12 5 7 9 11 13 Then create two 1D arrays to with row and column sum of the items. You have then 15 25 35 45 55 for the column sum, and 25 30 35 40 45 for the row sum. Print row...

  • C++ Lab 11 – Is This Box a Magic Box? Objectives: Define a two dimensional array Understand h...

    C++ Lab 11 – Is This Box a Magic Box? Objectives: Define a two dimensional array Understand how to traverse a two dimensional array Code and run a program that processes a two dimensional array Instructions: A magic square is a matrix (two dimensional arrays) in which the sum of each row, sum of each column, sum of the main diagonal, and sum of the reverse diagonal are all the same value. You are to code a program to determine...

  • in java / You will: // 1- create a square 2 dimensional array of random size...

    in java / You will: // 1- create a square 2 dimensional array of random size (less than 11) // 2- fill the array with random integers from 1 to the size limit // 3- print the array // 4- prompt to see if the user wants to do another //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // 1- The square can use the same random value for x and y. Don't allow 0 size arrays. // 2- Maybe a nested set of for loops? to...

  • In Java: Create an array of Integers with 10 elements, loop (use a for loop) through...

    In Java: Create an array of Integers with 10 elements, loop (use a for loop) through the array of integers printing their values to the screen. Create an array of Strings with 10 elements, loop (use a for loop) through the array of Strings printing their values to the screen. Finally, create an ArrayList of Integers. Use the loop from part 1 above and add each integer as you print it to the ArrayList as well, then start a final...

  • Using Python programming, create a 2-by-3 list, then use a nested loop to: 1) Set each...

    Using Python programming, create a 2-by-3 list, then use a nested loop to: 1) Set each element's value to an integer indicating the order in which it was processed by the nested loop (1, 2, 3, 4, 5, 6). 2) Display the elements in tabular format. Use the column indices as headings across the top, and the row indices to the left of each row.

  • please help fill out the class menu create a prototype that will display information about housing...

    please help fill out the class menu create a prototype that will display information about housing data1. In this prototype you will use dynamic array data structures to store the data and compute metrics. For the requirements of the prototype, your client has given you a list of metrics and operations. The user interface will be a menu that displays this list and prompts the user to choose which option to execute.You will create two classes. First you will create...

  • 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. * | 1 2 3 4 5 6 7 8 9 4 | 1| 1 2 3 456 7 8 9 2 | 2 4 6.8...

  • Write a python nested for loop that prints out the following pattern 100 99 98 97...

    Write a python nested for loop that prints out the following pattern 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 72 71 70 69 68 67 66 65 64 63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33...

  • c++ help please! Create a 2D character array in your main function and use nested for...

    c++ help please! Create a 2D character array in your main function and use nested for loops to fill the array with the letter ‘e’ to represent empty spaces. Create a function to print the board on the screen using a nested for loop. The function header is: void printBoard (char board [][3]) Create a function that checks whether a particular space has already been filled. If the space is filled it returns a boolean value of true, otherwise false....

  • create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array...

    create a new Java application called "Scorer" (without the quotation marks) that declares a two-dimensional array of doubles (call it scores) with three rows and three columns and that uses methods and loops as follows. Use a method containing a nested while loop to get the nine (3 x 3) doubles from the user at the command line. Use a method containing a nested for loop to compute the average of the doubles in each row. Use a method to...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT