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 print “hello world” without using semicolon?

0 Answers  


which of the following statements is incorrect a.typedef struct new{ int n1; char n2; } DATA; b.typedef struct { int n3; char *n4; }ICE; c.typedef union { int n5; float n6; } UDT; d.#typedef union { int n7; float n8; } TUDAT;

5 Answers   Assurgent, TCS,


what is the size of an integer variable?

4 Answers  


how is the examination pattern?

0 Answers   Wipro,


what is foreign key in c language?

1 Answers   ADP,






write a C code To reverse a linked list

2 Answers   Motorola, Wipro,


what is the difference between getch() and getche()?

7 Answers   Infosys,


Why do we use c for the speed of light?

0 Answers  


a parameter passed between a calling program and a called program a) variable b) constant c) argument d) all of the above

0 Answers  


a value that does not change during program execution a) variabe b) argument c) parameter d) none

0 Answers  


main() { char *p; p="Hello"; printf("%c\n",*&*p); }

2 Answers   ME,


Please write the area of a RIGHT ANGLED TRIANGLE.

1 Answers  


Categories