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

how we can say java is platform independent, while we require JVM for that particular Operating System?

3 Answers   Honeywell, TCS,


The variables are int sum=10,SuM=20; these are same or different?

3 Answers  


What are actual arguments?

0 Answers  


What does struct node * mean?

0 Answers  


program to find the roots of a quardratic equation

1 Answers  


what is op? for(c=0;c=1000;c++) printf("%c",c);

21 Answers   Trigent,


write a program to display all prime numbers

0 Answers  


What is zero based addressing?

0 Answers  


difference between object file and executable file

0 Answers  


Write a program to know whether the input number is an armstrong number.

0 Answers   Wipro,


What is operator promotion?

0 Answers  


How can I write functions that take a variable number of arguments?

0 Answers  


Categories