Using C++ Write a program which: 1. Assigns data given below into the 2D array o
ID: 3761999 • Letter: U
Question
Using C++ Write a program which:
1. Assigns data given below into the 2D array of integers which is 10x10
2. Prints out the contents of the 2D array after assigning the data to make sure correct data
was assigned.
3. Figures out and prints out the square root of the sum of ALL the elements in the 2D
array.
4. Figures out and prints out the average of ALL THE ELEMENTS in the 2D array.
5. Figures out and prints out the square root of the sum of the values of the elements of
EACH ROW in the 2D array.
6. Figures out and prints the average of EACH COLUMN in the 2D array.
7. Figures out and prints out the square root of the sum of the values on the diagonal from
upper left hand corner to bottom right hand corner.
8. Figures out and prints out the average of the values on the diagonal from upper right hand
corner to bottom left hand corner.
To make assigning the 100 values easy we will test with the following data:
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
21 22 23 24 25 26 27 28 29 30
31 32 33 34 35 36 37 38 39 40
41 42 43 44 45 46 47 48 49 50
51 52 53 54 55 56 57 58 59 60
61 62 63 64 65 66 67 68 69 70
71 72 73 74 75 76 77 78 79 80
81 82 83 84 85 86 87 88 89 90
91 92 93 94 95 96 97 98 99 100
Explanation / Answer
#include <iostream> using namespace std; int main() { int test[10][10] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,91,92,93,94,95,96,97,98,99,100} //printing matrix for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { cout << temp[i][j]; } Cout<<” ”; } // Figures out and prints out the square root of the sum of ALL the elements in the 2D array. int sumsquare=0; for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { sumsquare= sumsquare+ temp[i][j]; } } Float result = sqrt(sumsquare); cout<<" The square root of the sum of ALL the elements is = "<<result<<" "; // Float result1= sumsquare/(10*10); cout<<" The answer is = "<<result1<<" "; // for(int i=0;i<10;i++) { int eachsumsquare=0; for(int j=0;j<10;j++) { eachavgcol = eachavgcol + temp[i][j]; Float result3 = eachavgcol /10; cout<<" The average of each the elements in column is = "<<result3<<" "; } } // // for(int i=0;i<10;i++) { int eachsumsquare=0; for(int j=0;j<10;j++) { eachsumsquare = eachsumsquare + temp[j][i]; Float result2 = sqrt(eachsumsquare); cout<<" The square root of the sum of each the elements is = "<<result2<<" "; } } // // Figures out and prints out the sum of diagonal the elements in the 2D array. int sumsquarediag=0; for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { if(i==j) sumsquarediag = sumsquarediag + temp[i][j]; } } Float result4 = sqrt(sumsquarediag); cout<<" The square root of the sum of diagonal the elements is = "<<result4<<" "; // Figures out and prints out the square root of the sum of ALL the elements in the 2D array. int sumsquarediagrev=0; for(int i=0;i<10;i++) { for(int j=0;j<10;j++) { if((i+j)==10) sumsquarediagrev = sumsquarediagrev + temp[i][j]; } } Float result5 = sqrt(sumsquarediagrev); cout<<" The square root of the sum of diagonal the elements is = "<<result5<<" "; return 0; }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.