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

What is the output of the following progarm? #include<stdio.h> main( ) { int x,y=10; x=4; y=fact(x); printf(ā€œ%d\nā€,y); } unsigned int fact(int x) { return(x*fact(x-1)); } A. 24 B. 10 C. 4 D. none

2 Answers  


what is the basis for selection of arrays or pointers as data structure in a program

0 Answers   TCS,


Explain what is the heap?

0 Answers  


Juxtapose the use of override with new. What is shadowing?

1 Answers  


What is the difference between c and python?

0 Answers  






hi, which software companys will take,if d candidate's % is jst 55%?

0 Answers  


What would happen to X in this expression: X += 15; (assuming the value of X is 5)

0 Answers  


Write a program for the following series: 1*3*5-2*4*6+3*5*7-4*6*8+.................up to nterms

5 Answers   Convex Digital,


Explain how do you print an address?

0 Answers  


what is the mean of c languages.

1 Answers   Polaris,


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,


write a program for 7*8 = 56 ? without using * multiply operator ? output = 56

6 Answers   Xavient,


Categories