Rotate n x n MatrixCode CrazeFeb 23, 20231 min read#include <stdio.h>void main() { int m[100][100]; int i, j, s; printf("\nEnter square matrix size : "); scanf("%d", &s); for(j=0;j<s; j ++) { for(j=0;j<s; j ++) { printf("\nEnter element : "); scanf("%d",&m[i][j]); } } printf("\n----Current Matrix----\n\n"); for(i=0;i<s;i++) { for(j=0;j<s;j++) { printf(" %d",m[i][j]); } printf("\n"); } printf("\n----Matrix After 90 Degree Clockwise Rotation----\n\n"); for(i=0;i<s;i++) { for(j=s-1;j>=0;j--) { printf(" %d",m[j][i]); } printf("\n"); } printf("\n----Matrix After 90 Degree Anti-clockwise Rotation----\n\n"); for(i=s-1;i>=0;i--) { for(j=0;j<s;j++) { printf(" %d",m[j][i]); } printf("\n"); } printf("\n----Matrix After 180 Degree Rotation----\n\n"); for(i=s-1;i>=0;i--) { for(j=s-1;j>=0;j--) { printf(" %d ",m[i][j]); } printf("\n"); }}
#include <stdio.h>void main() { int m[100][100]; int i, j, s; printf("\nEnter square matrix size : "); scanf("%d", &s); for(j=0;j<s; j ++) { for(j=0;j<s; j ++) { printf("\nEnter element : "); scanf("%d",&m[i][j]); } } printf("\n----Current Matrix----\n\n"); for(i=0;i<s;i++) { for(j=0;j<s;j++) { printf(" %d",m[i][j]); } printf("\n"); } printf("\n----Matrix After 90 Degree Clockwise Rotation----\n\n"); for(i=0;i<s;i++) { for(j=s-1;j>=0;j--) { printf(" %d",m[j][i]); } printf("\n"); } printf("\n----Matrix After 90 Degree Anti-clockwise Rotation----\n\n"); for(i=s-1;i>=0;i--) { for(j=0;j<s;j++) { printf(" %d",m[j][i]); } printf("\n"); } printf("\n----Matrix After 180 Degree Rotation----\n\n"); for(i=s-1;i>=0;i--) { for(j=s-1;j>=0;j--) { printf(" %d ",m[i][j]); } printf("\n"); }}
Stack Using QueueA stack can be implemented using two queues in C. The basic idea is to use one queue for enqueue operations and another for dequeue...
Comments