forked from ThangaAyyanar/newapps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRotate_anticlockwise.c
65 lines (54 loc) · 1.16 KB
/
Rotate_anticlockwise.c
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
61
62
63
64
65
/*
Rotate Matrix 90 Degree Anti-Clockwise
A MxN matrix is passed as the input. The program must rotate the matrix by 90 degrees in anti-clock wise direction and print the rotated matrix as the output.
Input Format:
First line will contain the value of M.
Second line will contain the value of N.
Next M lines will contain the N values with each value separated by one or more space.
Output Format:
N lines will contain the M values with each value separated by one or more space.
Boundary Conditions:
2 <= M <= 15
2 <= N <= 15
Example Input/Output 1:
Input:
2
3
4 5 9
1 3 5
Output:
9 5
5 3
4 1
Example Input/Output 2:
Input:
4
4
1 2 3 4
5 6 7 8
9 10 11 12
13 14 15 16
Output:
4 8 12 16
3 7 11 15
2 6 10 14
1 5 9 13
*/
#include<stdio.h>
int main(){
int rows,cols,i,j;
scanf("%d %d",&rows,&cols);
int a[rows][cols];
for(i=0;i<rows;i++){
for(j=0;j<cols;j++){
scanf("%d",&a[i][j]);
}
}
for(j=cols-1;j>=0;j--){
for(i=0;i<rows;i++){
printf("%d ",a[i][j]);
}
printf("\n");
}
return 0;
}