Write a C++ program that declares the following 2 arrays: const int Rs = 8, Cs = 8; double arr[Rs][Cs]; double arr_quarter[Rs / 4][Cs / 4]; //fill in the array with some data for (int r = 0; r < Rs; r++) for (int c = 0; c < Cs; c++) arr[r][c] = r * 8 + c;
Computer Science
Write a C++ program that declares the following 2 arrays:
const int Rs = 8, Cs = 8;
double arr[Rs][Cs];
double arr_quarter[Rs / 4][Cs / 4];
//fill in the array with some data
for (int r = 0; r < Rs; r++)
for (int c = 0; c < Cs; c++)
arr[r][c] = r * 8 + c;
Then:
- Print out the diagonal of arr
- Print out the anti-diagonal of arr
- Downsize arr by a factor of 4 (i.e. Rs/4 and Cs/4) and store the result in arr_quarter. Then print it out.
- Then upsize arr_quarter by a factor of four and store the result in arr and print it out.
Expected output:
Print Array:
0 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
Diagonal elements:
0 9 18 27 36 45 54 63
Anti-diagonal elements:
7 14 21 28 35 42 49 56
Downsize an array (quarter Rs and Cs):
Print Array:
0 4
32 36
Upsize an array (Rs*4 and Cs*4):
Print Array:
0 0 0 0 4 4 4 4
0 0 0 0 4 4 4 4
0 0 0 0 4 4 4 4
0 0 0 0 4 4 4 4
32 32 32 32 36 36 36 36
32 32 32 32 36 36 36 36
32 32 32 32 36 36 36 36
32 32 32 32 36 36 36 36
Step by step
Solved in 3 steps with 1 images