Spiral Pattern


#include<stdio.h>

void main()
{
int a[5][5]={
1,2,3,4,5,
0,9,8,7,6,
5,4,3,2,1,
6,7,8,9,0,
0,2,4,6,8};
int i,j,c,n;
c=0;
n=5;
for(i=0;i<n;i++)
{
for(j=c;j<n-c;j++)
printf("%d",a[c][j]);
for(j=1+c;j<=n-c-1;j++)
printf("%d",a[j][n-c-1]);
for(j=n-c-2;j>=c;j--)
printf("%d",a[n-c-1][j]);
for(j=n-c-2;j>c;j--)
printf("%d",a[j][c]);
c++;
printf("\nc=%d\n",c);
}
}

Previous Post Next Post