how to display 2-D array elements in spiral

Answer Posted / raj

#define subscript 5


void spiral()
{
int a[subscript][subscript],i,j,k,l,m,p,q;
p=q=subscript ;
for(i=0;i<p;i++,p--)
{
for(j=i;j<n-1;j++)
printf("%d",a[i][j]);
for(k=i;k<j;k++)
printf("%d",a[k][j]);
for(l=k;l>i;l--)
printf("%d",a[l][k]);
for(m=k;m>i;m--)
printf("%d",a[i][m]);
}
if(q%2!=0)
printf("%d",a[j][j]);
}

Is This Answer Correct ?    2 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

a function gets called when the function name is followed by a a) semicolon (;) b) period(.) c) ! d) none of the above

863


What is the difference between memcpy and memmove?

597


What are the advantages of using linked list for tree construction?

639


Explain the use of 'auto' keyword in c programming?

677


Describe newline escape sequence with a sample program?

647






Write a C program to help a HiFi’s Restaurant automate its breakfast billing system. Your assignment should implement the following items: a. Show the customer the different breakfast items offered by the HiFi’s Restaurant. b. Allow the customer to select more than one item from the menu. c. Calculate and print the bill to the customer. d. Produce a report to present your complete program and show more sample output. Assume that the HiFi’s Restaurant offers the following breakfast menu: Plain Egg $2.50 Bacon and Egg $3.45 Muffin $2.20 French Toast $2.95 Fruit Basket $3.45 Cereal $0.70 Coffee $1.50 Tea $1.80

2550


What is the size of enum in c?

612


What is the importance of c in your views?

586


If the size of int data type is two bytes, what is the range of signed int data type?

581


What are identifiers and keywords in c?

564


write a program in C that prompts the user for today's date,tomorrow's date and display the results.Use structures for today's date,tomorrow's date and an array to hold the days for each month of the year.

4979


How do you use a pointer to a function?

625


What is the 'named constructor idiom'?

636


What are the 4 data types?

592


Write a program to produce the following output: 1 2 3 4 5 6 7 8 9 10

15043