bhupeshkumar99
BAN USER/*If an N X N matrix is given, print it in spiral order.
Example: Below is 5 X 5 matrix
i l o v e
d i n t e
n i e e p
a v w r i
m a x e c
*/
#include<stdio.h>
int main()
{
int row,col,i,move=0,j;
scanf("%d %d",&row,&col);
int inpMat[row][col];
for(i=0;i<row;i++)
{
for(j=0;j<col;j++)
scanf("%d",&inpMat[i][j]);
}
for(i=0;i<row/2;i++)
{
for(j=move;j<col-move;j++)
printf("%d",inpMat[move][j]);
for(j=move+1;j<row-move;j++)
printf("%d",inpMat[j][col-move-1]);
for(j=col-2-move;j>=move+1;j--)
printf("%d",inpMat[row-1-move][j]);
for(j=row-1-move;j>=move+1;j--)
printf("%d",inpMat[j][move]);
move++;
}
if(row%2!=0)
{
for(j=move;j<col-move;j++)
printf("%d",inpMat[move][j]);
}
}
cut 1:-cut vertically.
- bhupeshkumar99 May 25, 2013cut2:- superimpose the two pieces and cut again in two equal pieces.
cut3:- again follow step2.