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   To Refer this Site to Your Friends   Click Here
Google
 
Categories  >>  Code Snippets  >>  Programming Code  >>  C Code
 
 


 

 
 C Code interview questions  C Code Interview Questions
 C++ Code interview questions  C++ Code Interview Questions
 VC++ Code interview questions  VC++ Code Interview Questions
 Java Code interview questions  Java Code Interview Questions
 Dot Net Code interview questions  Dot Net Code Interview Questions
 Visual Basic Code interview questions  Visual Basic Code Interview Questions
 Programming Code AllOther interview questions  Programming Code AllOther Interview Questions
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  
 
  Re: Write a routine that prints out a 2-D array in spiral order
Answer
# 1
#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;
   }



 
Is This Answer Correct ?    1 Yes 3 No
Raghuram.A
 
  Re: Write a routine that prints out a 2-D array in spiral order
Answer
# 2
#include<stdio.h>
#include<conio.h>
#define n 4
void main()
{
	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;
	clrscr();
	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--;
	}
	getch();
}
 
Is This Answer Correct ?    10 Yes 3 No
Rajendra Kumar
 
 
 

 
 
 
Other C Code Interview Questions
 
  Question Asked @ Answers
 
main() { unsigned int i=10; while(i-->=0) printf("%u ",i); }  1
#define max 5 #define int arr1[max] main() { typedef char arr2[max]; arr1 list={0,1,2,3,4}; arr2 name="name"; printf("%d %s",list[0],name); }  1
main() { printf("%d, %d", sizeof('c'), sizeof(100)); } a. 2, 2 b. 2, 100 c. 4, 100 d. 4, 4 HCL1
How can u say that a given point is in a triangle? 1. with the co-ordinates of the 3 vertices specified. 2. with only the co-ordinates of the top vertex given.  1
main() { int c = 5; printf("%d", main||c); } a. 1 b. 5 c. 0 d. none of the above HCL1
Given an array of size N in which every number is between 1 and N, determine if there are any duplicates in it. You are allowed to destroy the array if you like. Microsoft14
void main() { char ch; for(ch=0;ch<=127;ch++) printf(“%c %d \n“, ch, ch); }  1
main() { int i =0;j=0; if(i && j++) printf("%d..%d",i++,j); printf("%d..%d,i,j); }  1
main() { char *str1="abcd"; char str2[]="abcd"; printf("%d %d %d",sizeof(str1),sizeof(str2),sizeof("abcd")); }  1
What is the problem with the following code segment? while ((fgets(receiving array,50,file_ptr)) != EOF) ;  1
How will u find whether a linked list has a loop or not? Microsoft6
main() { extern int i; i=20; printf("%d",sizeof(i)); }  1
main() { int i=5,j=6,z; printf("%d",i+++j); }  1
Write a function to find the depth of a binary tree. Adobe8
Is the following statement a declaration/definition. Find what does it mean? int (*x)[10];  1
main() { int *j; { int i=10; j=&i; } printf("%d",*j); }  1
Is the following code legal? typedef struct a { int x; aType *b; }aType  1
main(int argc, char *argv[]) { (main && argc) ? main(argc-1, NULL) : return 0; } a. Runtime error. b. Compile error. Illegal syntax c. Gets into Infinite loop d. None of the above HCL1
programming in c lanugaue programm will errror error with two header file one as stdio.h and other one is conio.h  1
main() { if (!(1&&0)) { printf("OK I am done."); } else { printf("OK I am gone."); } } a. OK I am done b. OK I am gone c. compile error d. none of the above HCL1
 
For more C Code Interview Questions Click Here 
 
 
 
 
 
   
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