question is in the picture in great need for answer in c pro
question is in the picture
in great need for answer in c programing language
T T
thx for ur kindly help_
Solution
code:
#include <bits/stdc++.h>
#define N 5
using namespace std;
void displayMatrix(int mat[N][N]);
void rotationMatrix(int mat[][N])
{
// Consider all squares one by one
for (int x = 0; x < N / 2; x++)
{
// Consider elements in group of 4 in
// current square
for (int y = x; y < N-x-1; y++)
{
// store current cell in temp variable
int temp = mat[x][y];
// move values from right to top
mat[x][y] = mat[y][N-1-x];
// move values from bottom to right
mat[y][N-1-x] = mat[N-1-x][N-1-y];
// move values from left to bottom
mat[N-1-x][N-1-y] = mat[N-1-y][x];
// assign temp to left
mat[N-1-y][x] = temp;
}
}
}
void displayMatrix(int mat[N][N])
{
for (int i = 0; i < N; i++)
{
for (int j = 0; j < N; j++)
printf(\"%2d \", mat[i][j]);
printf(\"\ \");
}
printf(\"\ \");
}
int main()
{
int mat[N][N];
for(int i=0;i<N;i++)
for (int j = 0; j < N; ++j)
{
cin>>mat[i][j];
}
char l;
while(true)
{
cout<<\"Enter L to rotate and any letter to exit\ \";
cin>>l;
if(l==\'L\')
{
rotationMatrix(mat);
displayMatrix(mat);
}
else
break;
}
return 0;
}
=================================================================================

