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

The difference between printf and fprintf is ?

714


What are loops in c?

545


What are local static variables? How can you use them?

641


Explain the ternary tree?

597


Do character constants represent numerical values?

837






how logic is used

1493


Explain how can you determine the size of an allocated portion of memory?

616


Explain with the aid of an example why arrays of structures don’t provide an efficient representation when it comes to adding and deleting records internal to the array.

2653


How to implement a packet in C

2391


How are variables declared in c?

597


Is file a keyword in c?

496


What are register variables? What are the advantage of using register variables?

678


Write a program to print ASCII code for a given digit.

680


What does struct node * mean?

595


Does c have an equivalent to pascals with statement?

570