ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip   SiteMap shows list of All Categories in this site.
Google
 
Categories >> Code-Snippets >> Programming-Code >> C-Code
 
 
 
Question
Write a routine that prints out a 2-D array in spiral order
 Question Submitted By :: =-pkg-=
I also faced this Question!!     Rank Answer Posted By  
 
Answer
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
main()
 {
 int n,m,i=0,j=0,k=0,l=0,p=0,q=1,r=0,s=1,a=40,b=25,ar[100];
 clrscr();
 cout<<"enter n:";
 cin>>n;
 printf("enter array elements:");
 for(m=0;m<n;m++)
 scanf("%d",&ar[m]);
 gotoxy(a,b);
 m=0;
 printf("%d",ar[m++]);
 while(m<n)
 {
 while(i<=j)
 {
 i++;
 a+=4;
 gotoxy(a,b);
 printf("%d",ar[m++]);
   if(m>=n)
   goto next;
   }

 while(k<=l)
 {   k++;
  b+=4;
 gotoxy(a,b);
 printf("%d",ar[m++]);
 if(m>=n)
 goto next;
 }
 while(p<=q)
 {
 p++;
 a-=4;
 gotoxy(a,b);
 printf("%d",ar[m++]);
 if(m>=n)
 goto next;

 }
 while(r<=s)
 {
  r++;
  b-=4;
  gotoxy(a,b);
  printf("%d",ar[m++]);
 if(m>=n)
 goto next;
 }
   j+=2;
   l+=2;
   q+=2;
   s+=2;
   i=0;
   k=0;
   p=0;
   r=0;

   }
   next:getch();
   return 0;
   }



 
2
Raghuram.A
 
View All Answers
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com