rajendra kumar


{ City } pune
< Country > india
* Profession *
User No # 17436
Total Questions Posted # 0
Total Answers Posted # 1

Total Answers Posted for My Questions # 0
Total Views for My Questions # 0

Users Marked my Answers as Correct # 27
Users Marked my Answers as Wrong # 11
Questions / { rajendra kumar }
Questions Answers Category Views Company eMail




Answers / { rajendra kumar }

Question { Microsoft, 16519 }

Write a routine that prints out a 2-D array in spiral order


Answer

#include
#include
#define n 4
void main()
{
int A[n][n]={{1,2,3,4},{5,6,7,8},{9,10,11,12},{13,14,15,16}};
int min=0,max=n-1,i,j;
clrscr();
while(min {
for(i=min;i<=max;i++)
printf("%d,",A[min][i]);
for(i=min+1;i<=max;i++)
printf("%d,",A[i][max]);
for(i=max-1;i>=min;i--)
printf("%d,",A[max][i]);
for(i=max-1;i>min;i--)
printf("%d,",A[i][min]);
min++;
max--;
}
getch();
}

Is This Answer Correct ?    27 Yes 11 No