-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotate array
More file actions
60 lines (51 loc) · 835 Bytes
/
Copy pathrotate array
File metadata and controls
60 lines (51 loc) · 835 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
50
51
52
53
54
55
56
57
58
59
60
#include<iostream>
using namespace std;
void rotate(int a[10][10],int n)
{
//for reversing
for(int r=0;r<n;r++)
{int x=0;
int y=n-1;
while(x<y)
{
swap(a[r][x],a[r][y]);
x++;
y--;
}
}
//for transpose
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
if(i<j)
{
swap(a[i][j],a[j][i]);
}
}
}
for (int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cout<<a[i][j]<<" ";
}
cout<<endl;
}
}
int main()
{
int a[10][10];
int n;
cin>>n;
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
cin>>a[i][j];
}
}
cout<<endl;
rotate(a,n);
return 0;
}