Question
Reverse Diagonal Write a function that reverses both the diagonals of a two-dimensional array with 4 rows and 4 columns but does not move any
Reverse Diagonal Write a function that reverses both the diagonals of a two-dimensional array with 4 rows and 4 columns but does not move any other elements of the array. void reverse_diagonal(int array[][4]); Files We Give You: A makefile and a sample main program (diagonal.cpp) to test your solution. The executable file created by a successful build will be named diagonal. File You Must Submit: Place your solution code in a file named solution.cpp. This will be the only file you submit. Examples Input: array = {{21, 26, 31, 36}, {41, 46, 51, 56}, {61, 66, 71, 76}, {81, 86, 91, 96}} Array before function is called: 21 26 31 36 41 46 51 56 61 66 71 76 81 86 91 96 Output: array = {{96, 26, 31, 81}, {41, 71, 66, 56}, {61, 51, 46, 76}, {36, 86, 91, 21}} Array after function has been called (elements that were moved are shown in red): 96 26 31 81 41 71 66 56 61 51 46 76 36 86 91 21 Input: array = {{35, 12, 27, 84}, {62, 19, 81, 32}, {74, 53, 29, 41}, {23, 60, 37, 15}} Array before function is called: 35 12 27 84 62 19 81 32 74 53 29 41 23 60 37 15 Output: array = {{15, 12, 27, 23}, {62, 29, 53, 32}, {74, 81, 19, 41}, {84, 60, 37, 35}} Array after function has been called (elements that were moved are shown in red): 15 12 27 23 62 29 53 32 74 81 19 41 84 60 37 35
BELOW IS THE GIVEN CPP FILE:
#include#include using std::cout; using std::endl; static void print_array(int array[][4]) { for (int row = 0; row < 4; row++) { for (int col = 0; col < 4; col++) { cout << array[row][col] << ' '; } cout << endl; } } void reverse_diagonal(int[][4]); int main() { int array1[4][4] = {{21, 26, 31, 36}, {41, 46, 51, 56}, {61, 66, 71, 76}, {81, 86, 91, 96}}; int array2[4][4] = {{35, 12, 27, 84}, {62, 19, 81, 32}, {74, 53, 29, 41}, {23, 60, 37, 15}}; cout << "Before: "; print_array(array1); reverse_diagonal(array1); cout << " After: "; print_array(array1); cout << endl; cout << "Before: "; print_array(array2); reverse_diagonal(array2); cout << " After: "; print_array(array2); return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started