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
 
 


 

 
 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
 
write a program to Insert in a sorted list Microsoft4
What is wrong with the following code? int *foo() { int *s = malloc(sizeof(int)100); assert(s != NULL); return s; }  1
main() { char *p = “ayqm”; char c; c = ++*p++; printf(“%c”,c); }  1
void main() { static int i=i++, j=j++, k=k++; printf(“i = %d j = %d k = %d”, i, j, k); }  1
main() { if ((1||0) && (0||1)) { 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
how to check whether a linked list is circular.  3
How to reverse a String without using C functions ? Wipro13
Give a one-line C expression to test whether a number is a power of 2. Microsoft8
main() { register int a=2; printf("Address of a = %d",&a); printf("Value of a = %d",a); }  1
To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. Synergy2
String reverse with time complexity of n/2 with out using temporary variable. NetApp8
main() { float i=1.5; switch(i) { case 1: printf("1"); case 2: printf("2"); default : printf("0"); } }  1
main() { int i=4,j=7; j = j || i++ && printf("YOU CAN"); printf("%d %d", i, j); }  1
main() { int i=-1,j=-1,k=0,l=2,m; m=i++&&j++&&k++||l++; printf("%d %d %d %d %d",i,j,k,l,m); }  1
main() { char string[]="Hello World"; display(string); } void display(char *string) { printf("%s",string); }  1
Is the following code legal? typedef struct a { int x; aType *b; }aType  1
main() { char a[4]="HELLO"; printf("%s",a); }  1
how to return a multiple value from a function? Wipro2
Sorting entire link list using selection sort and insertion sort and calculating their time complexity NetApp1
1 o 1 1 0 1 0 1 0 1 1 0 1 0 1 how to design this function format in c-language ?  1
 
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