Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How do you list files in a directory?

1139


When is a “switch” statement preferable over an “if” statement?

1138


Why are some ANSI/ISO Standard library routines showing up as undefined, even though I've got an ANSI compiler?

1125


What happens if header file is included twice?

1143


Can I initialize unions?

1037


What does sizeof function do?

1190


What is the purpose of sprintf() function?

1117


What is the difference between fread and fwrite function?

1077


How can you read a directory in a C program?

1141


how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software

3314


What is meant by type casting?

1052


What is the difference between the expression “++a” and “a++”?

1230


a single linked list consists of nodes a to z .print the nodes in reverse order from z to a using recursion

2776


Do you know null pointer?

1021


What is the difference between #include and #include 'file' ?

1050