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 (2265)
 C++ interview questions  C++ Interview Questions (1119)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (648)
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
#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 ?    2 Yes 0 No
Siraj-ud-doulla
 
Answer
# 8
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
# 9
#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
# 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 are local and global variables?   3
What is the output of the following progarm? #include<stdio.h> main( ) { int x,y=10; x=4; y=fact(x); printf(%d\n,y); } unsigned int fact(int x) { return(x*fact(x-1)); } A. 24 B. 10 C. 4 D. none   2
Why data types in all programming languages have some range? Why ritche have disigned first time likethat?Why not a single data type can support all other types? Excel 2
How to print all the 26 alphabets in this order in C. AbCdEfGh..... it should print dynamically from a to z and do not print this using pgm like this print("Ab......"); Use loops or anything to print all alphabets Hexaware 1
long int size a) 4 bytes b) 2 bytes c) compiler dependent d) 8 bytes HCL 18
How does free() know how many bytes to free?   8
write a program that will print %d in the output screen?? Infosys 7
I didn't count the ducks that I saw in line, but I do remember that one duck was in front of two ducks, another duck behind two ducks. How many ducks did I see?   2
yogesh patil in dell DELL 3
WAP that prints the number from 1 to 100. but for multiplies of three print "XXX" instead of the number and for the multiplies of five print "YYY" . for number which are multiplies of both three and five print "ZZZ"   2
what is the difference b/w compiler and debugger? Assurgent 2
what is the use of operator ^ in C ? and how it works?   2
 
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