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

why java is called as a purely oops language.

3 Answers   TVS,


What is a newline escape sequence?

0 Answers  


Iam a B.Tech graduate and completed my engineering in 2009, from 2005 to 2009 and after that i had done nothing.Now i want to do job and get into BPO field . Friends give me suggestions as what to say in interview... if they ask me that what would you had done ... these many years without doing job ??????? pls urgent

0 Answers  


What are data structures in c and how to use them?

0 Answers  


Without using main fn and semicolon,print remainder for a given number in C language

2 Answers  






If I want to initialize the array like. int a[5] = {0}; then it gives me all element 0. but if i give int a[5] = {5}; then 5 0 0 0 0 is ans. what will I do for all element 5 5 5 5 5 in a single statement???

3 Answers   Amdocs, IBM,


What is extern variable in c with example?

0 Answers  


Write a program to display the no of bit difference between any 2 given numbers eg: Num1 will 12->1100 Num2 will 7->0111 the difference in bits are 2.

4 Answers  


What is #include cctype?

0 Answers  


program for following output using for loop? 1 2 3 4 5 2 3 4 5 3 4 5 4 5 5

8 Answers   Infosys,


what is the hexidecimal number of 4100?

16 Answers   Google,


Give a fast way to multiply a number by 7

15 Answers   Accenture, Aricent, Microsoft,


Categories