Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

The problem is: Write and compile a C++ program that creates a two-dimensional a

ID: 3650015 • Letter: T

Question

The problem is:

Write and compile a C++ program that creates a two-dimensional array initialized with the following data, namely { {1, 2, 3, 4, 5}, {27, 14, 8, 0, 0}, {9, 6, 18, 111, 35} }. Next, pass this two-dimensional array to a separate function that reverses the order of the elements in each of the three rows. Once this is complete, the main function should print out each of the rows to confirm that they have been successfully reversed.


Im just not sure how to reverse the array.

What I have so far:

#include <iostream>
using namespace std;

const unsigned int R_SIZE = 3;
const unsigned int C_SIZE = 5;
void Reverse(int[][C_SIZE], int);


int main()
{

int Array[R_SIZE][C_SIZE] = {{1, 2, 3, 4, 5}, {27, 14, 8, 0, 0}, {9, 6, 18, 111, 35}};
int i;
int j;

Reverse(Array, 3);

return 0;
}


void Reverse(int Array[][C_SIZE], int R_SIZE)
{

}

Explanation / Answer

please rate - thanks

#include <iostream>
using namespace std;
const unsigned int R_SIZE = 3;
const unsigned int C_SIZE = 5;
void Reverse(int[][C_SIZE]);
int main()
{int Array[R_SIZE][C_SIZE]={ {1, 2, 3, 4, 5}, {27, 14, 8, 0, 0}, {9, 6, 18, 111, 35} };
int i,j;
cout<<"before reversed ";
for(i=0;i<R_SIZE;i++)
    {for(j=0;j<C_SIZE;j++)
        cout<<Array[i][j]<<" ";
     cout<<endl;
     }
Reverse(Array);
cout<<" after reversed ";
for(i=0;i<R_SIZE;i++)
    {for(j=0;j<C_SIZE;j++)
        cout<<Array[i][j]<<" ";
     cout<<endl;
     }

system("pause");                                                                                         
return 0;
}
void Reverse( int a[][5])
{int i,j,t;
for(i=0;i<R_SIZE;i++)
     for(j=0;j<C_SIZE/2;j++)
          {t=a[i][j];
          a[i][j]=a[i][C_SIZE-1-j];
          a[i][C_SIZE-1-j]=t;
          }
}