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

In C language, a variable name cannot contain?

704


Is the exit() function same as the return statement? Explain.

642


write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.

1956


What is string length in c?

577


What is methods in c?

607






What is memcpy() function?

597


How can I manipulate individual bits?

579


Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?

574


How do you override a defined macro?

663


How can I use a preprocessorif expression to ?

581


Why do we use c for the speed of light?

586


Tell me with an example the self-referential structure?

540


Explain two-dimensional array.

593


Explain can you assign a different address to an array tag?

616


program for reversing a selected line word by word when multiple lines are given without using strrev

1921