C+ arrays create C + program that utilizes arrays C +program that reverses the e
ID: 3597476 • Letter: C
Question
C+ arrays create C + program that utilizes arrays C +program that reverses the elements into dimensional arrays assuming you have a matrix of size m x n the element in position (0,0)will be swapped with the element position (M -1, n-1). The element position is zero, one will be exchange with the element position (m-1, n-2 )and so on An enumeration, and basic properties of the combo box and numeric up down controlled by creating event procedures for menu controls.C+ arrays create C + program that utilizes arrays C +program that reverses the elements into dimensional arrays assuming you have a matrix of size m x n the element in position (0,0)will be swapped with the element position (M -1, n-1). The element position is zero, one will be exchange with the element position (m-1, n-2 )and so on An enumeration, and basic properties of the combo box and numeric up down controlled by creating event procedures for menu controls.
C+ arrays An enumeration, and basic properties of the combo box and numeric up down controlled by creating event procedures for menu controls.
Explanation / Answer
// c++ code segment
#include<iostream>
#include<bits/stdc++.h>
#define max_row 5
#define max_col 5
using namespace std;
void reverseMatrix(int arr[max_row][max_col], int row, int col) //reversing the array by 180 degree
{
int i,j,temp;
for(i=0;i<=max_row/2;i++) //1st swap 1st row with last row , 2nd row with 2nd last row and so on . till we go to the middle row
{
if(row<=i)
break;
for(j=0;j < col;j++)
{
temp=arr[i][j];
arr[i][j]=arr[row-1][j];
arr[row-1][j]=temp;
}
row--;
}
row = max_row;
for(j=0;j<=max_col/2;j++) ////next swap 1st row with last row , 2nd row with 2nd last row and so on . till we go to the middle row
{
if(col<=j)
break;
for(i=0;i < row;i++)
{
temp=arr[i][j];
arr[i][j]=arr[i][col-1];
arr[i][col-1]=temp;
}
col--;
}
}
void displayMatrx(int arr[max_row][max_col], int row, int col) // displays the matrix
{
int i,j;
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
{
cout<<arr[i][j]<<" ";
}
cout<<endl;;
}
}
int main()
{
int arr[max_row][max_col] = {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};
int row=max_row;
int col = max_col;
int i,j;
cout<<"Before Rotation"<<endl;
displayMatrx(arr,row,col);
cout<<"Menu"<<endl;
cout<<"1.Reverse Matrix"<<endl; // menu driven option
cout<<"2.Display Matrix"<<endl;
char ch;
cin>>ch;
if(ch=='1')
{
cout<<"After Rotation"<<endl;
reverseMatrix(arr,row,col);
displayMatrx(arr,row,col);
}
else if ( ch = '2' )
{
displayMatrx(arr,row,col);
}
else
cout<<"Invalid Input"<<endl;
getchar();
return 0;
}
// Sample out
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.