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

What is d'n in c?

798


What are c identifiers?

830


#include #include struct stu { int i; char j; }; union uni { int i; char j; }; void main() { int j,k; clrscr(); struct stu s; j=sizeof(s); printf("%d",j); union uni u; k=sizeof(u); printf("%d",k); getch(); } what is value of j and k.

5714


What happens if a header file is included twice?

768


Are comments included during the compilation stage and placed in the EXE file as well?

858


Give differences between - new and malloc() , delete and free() ?

822


What is a substring in c?

772


Why does everyone say not to use gets?

792


can anyone please tell about the nested interrupts?

1849


What could possibly be the problem if a valid function name such as tolower() is being reported by the C compiler as undefined?

995


What is the scope of static variable in c?

704


What are actual arguments?

827


How can I copy just a portion of a string?

1041


In C, What is the #line used for?

1461


Can variables be declared anywhere in c?

816