Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
RotateMat
//g++ 7.4.0 //rotate matrix: another version of matrix rotation // //rotate function code credit goes to John R Hubbard,University of Richmond; read function and test driver codes are created by Rezaul Hoque on August 03,2021;contact: jewelmrh @yahoo.com //note: codes shared by Rezaul Hoque on rextester are not for sale; they are created and shared to facilitate the algorithm learning process; many like Hoque use this platform to practice programming ;Rezaul hopes his contribution helps others to fine tune their learning; #include <iostream> using namespace std; const int n=3; void rotate(int [][3],const int); void read(int [][3]); void read(int a[3][3]){ cout<<"Enter 9 integers,3 per row:\n"; for(int i=0;i<3;i++){ for(int j=0;j<3;j++) cin>>a[i][j]; } cout<<"Initial matrix:\n"; for(int i=0;i<3;i++){ cout<<"\n"; for(int j=0;j<3;j++) cout<<" "<<a[i][j]; } } void rotate(int m[][3],const int n){ int temp[n][n]; int i,j; for(i=0;i<n;i++){ for(j=0;j<n;j++) temp[i][j]= m[n-j-1][i]; } for(i=0;i<n;i++){ for(j=0;j<n;j++) m[i][j]= temp[i][j] ; } for(int i=0;i<3;i++){ cout<<"\n"; for(int j=0;j<3;j++) cout<<" "<<m[i][j]; } } int main() { int a[3][3]; read(a); cout<<"\nAfter 90° rotation:\n"; rotate(a,n); return 0; }
run
|
edit
|
history
|
help
0
tree
Factoriel
cppPyEnum
compute power to a number manually, and by using function.
SubprogramModificat
Dar
Scope guarding
Top view of a Binary tree
Test 5(2020)
sample