-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathRotateImage.cpp
More file actions
49 lines (37 loc) · 807 Bytes
/
RotateImage.cpp
File metadata and controls
49 lines (37 loc) · 807 Bytes
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
//Program to rotate the image(2D matrix)
void rotateImage(int a[][100], int m, int n){
//reverse the Row of matrix
for(int i=0;i<m;++i){
reverse(a[i],a[i]+n);
}
//Transpose the half Matrix
for(int i=0;i<m;++i){
for(int j=0;j<n;++j){
if(i<j)
swap(a[i][j],a[j][i]);
}
}
}
void display(int a[][100], int m, int n){
for(int i=0;i<m;++i){
for(int j=0;j<n;++j){
cout<< a[i][j]<<" ";
}
cout<<endl;
}
}
int main() {
int m, n;
cin>>m>>n;
int a[100][100];
for(int i=0;i<m;++i){
for(int j=0;j<n;++j){
cin>>a[i][j];
}
}
rotateImage(a,m,n);
display(a,m,n);
}