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


Please Help Members By Posting Answers For Below Questions

Where static variables are stored in c?

593


What are identifiers in c?

640


How do I get a null pointer in my programs?

626


What are local variables c?

556


Differentiate between calloc and malloc.

762






What is the hardest programming language?

673


code for quick sort?

1626


Write a program to find factorial of a number using recursive function.

650


What is fflush() function?

649


How to Throw some light on the splay trees?

623


What does a pointer variable always consist of?

667


Why cant I open a file by its explicit path?

598


What are structure types in C?

677


What is a substring in c?

592


Which is better between malloc and calloc?

673