Write a routine that prints out a 2-D array in spiral order!
Answer Posted / gajender singh
#define n 4
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;
while(min<max)
{
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--;
}
| Is This Answer Correct ? | 17 Yes | 11 No |
Post New Answer View All Answers
Which built-in library function can be used to match a patter from the string?
What are the different types of data structures in c?
What is preprocessor with example?
write a c program to calculate sum of digits till it reduces to a single digit using recursion
Write a C program to accept a matrix of any size. Find the frequency count of each element in the matrix and positions in which they appear in the matrix
while initialization of array why we use a[][2] why not a[2][]...?
Who developed c language and when?
If null and 0 are equivalent as null pointer constants, which should I use?
What's the right way to use errno?
What is bss in c?
Why is this loop always executing once?
Can you explain the four storage classes in C?
What are header files? What are their uses?
Can the “if” function be used in comparing strings?
What is the difference between far and near in c?