Write a routine that prints out a 2-D array in spiral order!
Answer Posted / 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 View All Answers
How do you list files in a directory?
When is a “switch” statement preferable over an “if” statement?
Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?
What happens if header file is included twice?
Can I initialize unions?
What does sizeof function do?
What is the purpose of sprintf() function?
What is the difference between fread and fwrite function?
How can you read a directory in a C program?
how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software
What is meant by type casting?
What is the difference between the expression “++a” and “a++”?
a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion
Do you know null pointer?
What is the difference between #include and #include 'file' ?