Write a routine that prints out a 2-D array in spiral order

Answer Posted / mahfooz

#include<stdio.h>
#define n 3
int main()
{
int arr[n][n]={{1,2,3},{4,5,6,},{7,8,9}};
int min=0,max=n-1,i;
while(min<=max)
{
for(i=min;i<=max;i++)
printf("%d ",arr[min][i]);
for(i=min+1;i<=max;i++)
printf("%d ",arr[i][max]);
for(i=max-1;i>=min;i--)
printf("%d ",arr[max][i]);
for(i=max-1;i>min;i--)
printf("%d ",arr[i][min]);
min++;
max--;
}
if(min==max) //this for odd case as n=3,5 etc
printf("%d \n",arr[min][min]);
return 0;
}

Is This Answer Correct ?    8 Yes 7 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

#include int main(void) { int a=4, b=2; a=b<>2 ; printf("%d",a); return 0; }

1054


What is the difference between proc means and proc tabulate ? explain with a simple example when you have to use means or tabulate?

3695


create a C-code that will display the total fare of a passenger of a taxi if the driver press enter,the timer will stop. Every 10 counts is 2 pesos. Initial value is 25.00

6293


could you please send the program code for multiplying sparse matrix in c????

3057


how to create a 3x3 two dimensional array that will give you the sums on the left and bottom columns

3108






why do you use macros? Explain a situation where you had to incorporate macros in your proc report? use a simple instream data example with code ?

2246


How can I Create a C program in splitting set of characters to specific subsets. Example: INPUT SET OF CHARACTERS: Therefore, my dear brothers and sisters, stand firm. Let nothing move you. Always give yourselves fully to the work of the Lord, because you know that your labor in the Lord is not in vain. SPLIT INTO HOW MANY CHARACTERS PER SUBSETS: 10 OUTPUT: Therefore, my dear b rothers an d sisters, stand fir m. Let not hing move you. Alway s give you rselves fu lly to the work of t he Lord, b ecause you know that your labo r in the L ord is not in vain.

1912


Sir... please give some important coding questions asked by product companies..

1781


can you use proc sql to manpulate a data set or would u prefer to use proc report ? if so why ? make up an example and explain in detail

2309


What is data _null_? ,Explain with code when u need to use it in data step programming ?

2804


Can you send Code for Run Length Encoding Of BMP Image in C Language in linux(i.e Compression and Decompression) ?

3834


To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']

481


Given a spherical surface, write bump-mapping procedure to generate the bumpy surface of an orange

2845


How can you relate the function with the structure? Explain with an appropriate example.

2905


write a program for area of circumference of shapes

2020