Author: Gour Ch. Saha
Contact for any query:: gour_ch_saha@yahoo.co.in
#include<stdio.h>
#define MAX_ROW 4
#define MAX_COL 4

main()
{
	int A[MAX_ROW][MAX_COL]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
	int i;
	int mincol , maxcol , minrow , maxrow;
	int cnt=0;
	int totalcnt;
	mincol=0;
	maxcol=MAX_COL - 1;

	minrow=0;
	maxrow=MAX_ROW - 1;

	totalcnt= MAX_ROW * MAX_COL;

	while(cnt<totalcnt)
	{
		for(i=mincol;i<=maxcol && cnt<totalcnt;i++)
		{
			printf("%d,",A[minrow][i]);
			cnt++;
		}
		for(i=minrow+1;i<=maxrow && cnt<totalcnt;i++)
		{
			printf("%d,",A[i][maxcol]);
			cnt++;
		}
		for(i=maxcol-1;i>=mincol && cnt<totalcnt;i--)
		{
			printf("%d,",A[maxrow][i]);
			cnt++;
		}
		for(i=maxrow-1;i>minrow && cnt<totalcnt;i--)
		{
			printf("%d,",A[i][mincol]);
			cnt++;
		}
		minrow++;
		maxrow--;
		mincol++;
		maxcol--;
	}
	printf("\n");

}


Free Web Hosting