-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrotation.cpp
More file actions
53 lines (51 loc) · 873 Bytes
/
rotation.cpp
File metadata and controls
53 lines (51 loc) · 873 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
#include<stdio.h>
#include<malloc.h>
int main()
{
int **a,n,t,i,j,f,l,temp;
printf("enter the dimension of square matrix:");
scanf("%d",&n);
a=(int**)malloc(n*sizeof(int*));
for(i=0;i<n;i++)
a[i]=(int*)malloc(n*sizeof(int));
for(i=0;i<n;i++)
for(j=0;j<n;j++)
{
printf("enter element in %d row and %d column:",(i+1),(j+1));
scanf("%d",&a[i][j]);
}
printf("The original matrix is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
for(i=0;i<n;i++)
for(j=i+1;j<n;j++)
{
t=a[i][j];
a[i][j]=a[j][i];
a[j][i]=t;
}
for(i=0;i<n;i++)
{
f=0;
l=n-1;
while(f<l)
{
temp=a[i][f];
a[i][f]=a[i][l];
a[i][l]=temp;
f++;
l--;
}
}
printf("The matrix after rotation of 90 degrees:\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
printf("%d\t",a[i][j]);
printf("\n");
}
}