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



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

Answer / 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

More C Interview Questions

write a program for size of a data type without using sizeof() operator?

22 Answers   HCL, IBM,


Define function pointers?

1 Answers  


What do you mean by c?

0 Answers  


What are qualifiers and modifiers c?

0 Answers  


what is the basis for selection of arrays or pointers as data structure in a program

0 Answers   TCS,






what is op? for(c=0;c=1000;c++) printf("%c",c);

21 Answers   Trigent,


What is Full Form of C and Why We use C

23 Answers  


hi any body pls give me company name interview conduct "c" language only

0 Answers  


What is a null string in c?

0 Answers  


ratio,age,persentage

0 Answers  


I have a function which accepts, and is supposed to initialize,a pointer, but the pointer in the caller remains unchanged.

1 Answers  


Can you mix old-style and new-style function syntax?

0 Answers  


Categories