Skip to content

Instantly share code, notes, and snippets.

@ivorynoise
Created June 7, 2018 20:24
Show Gist options
  • Save ivorynoise/a88f3728619f4dd25075c4cd591088e8 to your computer and use it in GitHub Desktop.
Save ivorynoise/a88f3728619f4dd25075c4cd591088e8 to your computer and use it in GitHub Desktop.
// Deepak Aggarwal, Coding Blocks
// deepak@codingblocks.com
#include <iostream>
using namespace std;
void inputMat(char mat[][10], int m, int n){
for(int r = 0; r < m; ++r){
for(int c = 0; c < n; ++c){
cin >> mat[r][c];
}
}
}
void outputMat(char mat[][10], int m, int n){
cout << "\n-----MAT Begins----\n";
for(int r = 0; r < m; ++r){
for(int c = 0; c < n; ++c){
cout << mat[r][c] << " ";
}
cout << endl;
}
cout << "-----MAT Ends------\n";
}
void rotateMat(char mat[][10], int n){
for(int rot = 0; rot < n / 2; ++rot){
for(int j = rot; j < n - 1 - rot; ++j){
char tmp = mat[rot][j];
swap(tmp, mat[j][n-1-rot]);
swap(tmp, mat[n-1-rot][n-1-j]);
swap(tmp, mat[n-1-j][rot]);
swap(tmp, mat[rot][j]);
}
}
}
int main(){
char mat[10][10];
int n;cin >> n;
inputMat(mat, n,n);
outputMat(mat, n, n);
rotateMat(mat, n);
outputMat(mat, n, n);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment