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
In C language, a variable name cannot contain?
Is the exit() function same as the return statement? Explain.
write a program that reads lines(using getline), converts each line to an integer using atoi, and computes the average of all the numbers read. also compute the standard deviation.
What is string length in c?
What is methods in c?
What is memcpy() function?
How can I manipulate individual bits?
Explain what is the difference between a string copy (strcpy) and a memory copy (memcpy)? When should each be used?
How do you override a defined macro?
How can I use a preprocessorif expression to ?
Why do we use c for the speed of light?
Tell me with an example the self-referential structure?
Explain two-dimensional array.
Explain can you assign a different address to an array tag?
program for reversing a selected line word by word when multiple lines are given without using strrev