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
The difference between printf and fprintf is ?
What are loops in c?
What are local static variables? How can you use them?
Explain the ternary tree?
Do character constants represent numerical values?
how logic is used
Explain how can you determine the size of an allocated portion of memory?
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.
How to implement a packet in C
How are variables declared in c?
Is file a keyword in c?
What are register variables? What are the advantage of using register variables?
Write a program to print ASCII code for a given digit.
What does struct node * mean?
Does c have an equivalent to pascals with statement?