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
Where static variables are stored in c?
What are identifiers in c?
How do I get a null pointer in my programs?
What are local variables c?
Differentiate between calloc and malloc.
What is the hardest programming language?
code for quick sort?
Write a program to find factorial of a number using recursive function.
What is fflush() function?
How to Throw some light on the splay trees?
What does a pointer variable always consist of?
Why cant I open a file by its explicit path?
What are structure types in C?
What is a substring in c?
Which is better between malloc and calloc?