ALLInterview.com :: Home Page            
 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                      
Google
   
 
Categories >> Software >> Programming Languages >> C
 
 


 

 
 C interview questions  C Interview Questions (2262)
 C++ interview questions  C++ Interview Questions (1118)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (647)
Question
write a program to display the array elements in reverse
order in c language
 Question Submitted By :: C
I also faced this Question!!     Answer Posted By  
 
Answer
# 1
void main()
{
int a[10],i,n;
printf("enter howmany elements");
scanf("%d",&n);

for(i=0;i<=n;i++)
scanf("%d",&a[i]);

for(i=n;i>=0;i--)
printf("%d",a[i]);

}
 
Is This Answer Correct ?    242 Yes 113 No
Vishnu948923
 
Answer
# 2
Both the solution above is wrong...

Answer #1: It will input an extra element in array coz array is starting from 0 and goes till n so total elements n+1

Answer #2: C Automatically starts array from 0 index and not 1 if not programmed otherwise and in the given program we are starting the loop from 1

Solution

void main()
{
int a[30],n;
scanf("%d",&n);

for(int i=0;i<n;i++)
scanf("%d",&a[i]);

for(i=n-1;i>=0;i--)
printf("%d",a[i]);

}
}
 
Is This Answer Correct ?    62 Yes 34 No
Arpit Dhandhania
 
 
 
Answer
# 3
The above solution is ritee.. :-)

cheers..
 
Is This Answer Correct ?    85 Yes 59 No
Shruti
 
Answer
# 4
#include<stdio.h>
int main()
{
int a[]={1,2,3,7,8};
int count=0,i;
while(a[i] != '\0')
{
count++;
}
for(i=count;i>=1;i--)
{
printf("%d",a[i]);
}
}
 
Is This Answer Correct ?    33 Yes 25 No
Pandia
 
Answer
# 5
#include<stdio.h>
int main()
{
int a[]={1,2,3,7,8};
int count=0,i;
while(a[i] != '\0')
{
count++;
}
for(i=count;i>=1;i--)
{
printf("%d",a[i]);
}
}
 
Is This Answer Correct ?    50 Yes 44 No
Dally
 
Answer
# 6
#include<stdio.h>
#include<conio.h>
void main()
{
int a[],n;
printf("enter array size");
scanf("%d",&n);
printf("enter elements of an array");
for(i=0;i<n;i++)
{
scanf("%d",a[i]);
}
for(i=1;i<=n;i++)
{
printf("%d",a[n-i]);
}
getch();
}
 
Is This Answer Correct ?    4 Yes 0 No
Tej
 
Answer
# 7
Actually i haven't any idea on array in reverse order. If
anyone will give dis answer, i'll be grateful to him/her.
And plz, tell me in brief.
thnk u..
 
Is This Answer Correct ?    1 Yes 0 No
Bhikshuk Patel
 
Answer
# 8
#include<stdio.h>

main()
{
int n, c, d, a[100], b[100];

printf("Enter the number of elements in array\n");
scanf("%d",&n);

printf("Enter the array elements\n");

for ( c = 0 ; c < n ; c++ )
scanf("%d",&a[c]);

for ( c = n - 1, d = 0 ; c >= 0 ; c--, d++ )
b[d] = a[c];

for ( c = 0 ; c < n ; c++ )
a[c] = b[c];

printf("Reverse array is\n");

for( c = 0 ; c < n ; c++ )
printf("%d\n", a[c]);

return 0;
}
 
Is This Answer Correct ?    3 Yes 2 No
Prajot Chougale
 
Answer
# 9
#include<stdio.h>

int main()
{
int n,i;
printf("How many number you get \n:");
scanf("%d",&n);
int arr[n];
printf("You need %d numbers\n",n);
for(i=0;i<n;i++){
scanf("%d",&arr[i]);
}
printf("Revarse number is:\n");
for(i=n-1;i>=0;i--){
printf("%d\n",arr[i]);
}
return 0;

}
 
Is This Answer Correct ?    1 Yes 0 No
Siraj-ud-doulla
 
Answer
# 10
all the answers are not working ... it compiles well but does not give any thing in return just keeps on taking in put and no output :| 
Is This Answer Correct ?    2 Yes 2 No
Pixie
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
what is constant pointer?   3
difference between spiral and waterfall model   1
Is it possible to run using programming C for Java Application? NIC 1
Switch (i) i=1; case 1 i++; case 2 ++i; break; case 3 --i; Output of i after executing the program Mascot 5
main() { int i=5; printf("%d%d%d%d",i++,i--,i); }   10
int a=2,b=3,c=4; printf("a=%d,b=%d\n",a,b,c); what is the o/p? Verifone 6
find second largest element in array w/o using sorting techniques? use onle one for loop. Zycus-Infotech 15
can we write a program in c for printf and scanf without using header file stdio.h   1
increment operateor (++)and decrament(--) #include<stdio.h> #inclide<conio.h> main() { int x=15; while(x!=0) scanf("%d",&x); { TCS 2
write a program for size of a data type without using sizeof() operator? IBM 21
what is the difference between procedure oriented and object oriented progaming language   1
a number is perfect if it is equal to the sum of its proper divisor.. 6 is perfect number coz its proper divisors are 1,2 and three.. and 1+2+3=6... a number is deficient if the sum of its proper divisor is less than the number.. sample: 8 is deficient, coz its proper divisors are 1,2 and 4, and 1+2+4=7. abundant number, if the sum of its proper divisor is greater than the number.. sample..12 is abundant coz 1+2+3+4+6=16 which is geater than 12. now write a program that prompts the user for a number, then determines whether the number is perfect,deficient and abundant..   1
 
For more C Interview Questions Click Here 
 
 
 
 
 


   
Copyright Policy  |  Terms of Service  |  Articles  |  Site Map  |  RSS Site Map  |  Contact Us
   
Copyright 2013  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  KalAajKal.com