forked from TECHOUS/DSKaKhel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRotateMatrixBy90.cpp
More file actions
41 lines (39 loc) · 833 Bytes
/
RotateMatrixBy90.cpp
File metadata and controls
41 lines (39 loc) · 833 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
#include<stdio.h>
#include<malloc.h>
#define size 3
void rotate90clockwise(int arr[size][size])
{
for(int i = 0 ; i < size/2 ; i++ )
{
for(int j = 0 ; j < size - i - 1 ; j++)
{
int temp = arr[i][j];
arr[i][j] = arr[size - 1 -j][i];
arr[size-1-j][i] = arr[size-1- i][size-1-j];
arr[size-1-i][size-1-j] = arr[j][size-1-i];
arr[j][size-1-i] = temp;
}
}
}
void printMatrix(int arr[size][size])
{
for (int i = 0; i < size; i++) {
for (int j = 0; j < size; j++)
printf("%d ",arr[i][j]);
printf("\n");
}
}
int main()
{
int arr[size][size];
for(int i = 0 ; i < size ; i++)
{
for(int j = 0 ; j < size ; j++)
{
scanf("%d",&arr[i][j]);
}
}
rotate90clockwise(arr);
printf("The printed matrix is \n");
printMatrix(arr);
}