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 to find given number is even or odd without using any control statement.

2 Answers  


Does * p ++ increment p or what it points to?

0 Answers  


find a number whether it is even or odd without using any control structures and relational operators?

22 Answers   Microsoft, Shashank Private Limited,


what is the difference between while and do while?

2 Answers  


Write the syntax and purpose of a switch statement in C.

0 Answers   Adobe,






What does static mean in c?

1 Answers  


write a progam to display the factors of a given number and disply how many prime numbers are there?

2 Answers  


What is #define used for in c?

0 Answers  


What are the preprocessors?

9 Answers   HP,


a way in which a pointer stores the address of a pointer which stores the value of the target value a) reference b) allocation c) multiple indirection d) none

0 Answers  


What is struct node in c?

0 Answers  


What is the deal on sprintf_s return value?

0 Answers  


Categories