Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int MAX_ROW=20;
- void swap (int &a, int &b)
- {
- int t=a;
- a=b;
- b=t;
- }
- void reverseDiagonal(int matrix[MAX_ROW][MAX_ROW], int row)
- {
- for(int i=0;i<row/2;i++)
- {
- swap(matrix[i][i],matrix[row-i-1][row-i-1]);
- swap(matrix[row-i-1][i],matrix[i][row-i-1]);
- }
- }
- void printMatrix(int matrix[MAX_ROW][MAX_ROW], int row)
- {
- for(int i=0;i<row;i++)
- {
- for(int j=0;j<row;j++)
- {
- cout<<matrix[i][j]<< " ";
- }
- cout<<endl;
- }
- }
- int main(){
- cout<<"First case: "<<endl;
- int myMatrix[MAX_ROW][MAX_ROW]={{96, 26 ,31 ,81},{41, 71, 66, 56},{61, 51, 46, 76},{36, 86, 91, 21}};
- printMatrix(myMatrix, 4);
- reverseDiagonal(myMatrix, 4);
- cout<<"After reverse Diagonal: "<<endl;
- printMatrix(myMatrix, 4);
- cout<<"Second case: "<<endl;
- int myMatrix2[MAX_ROW][MAX_ROW]={{1, 2 ,3 ,4,5},{1, 2 ,3 ,4,5},{1, 2 ,3 ,4,5},{1, 2 ,3 ,4,5},{1, 2 ,3 ,4,5}};
- printMatrix(myMatrix2, 5);
- reverseDiagonal(myMatrix2, 5);
- cout<<"After reverse Diagonal: "<<endl;
- printMatrix(myMatrix2, 5);
- system("pause");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement