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  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
write a program to display the array elements in reverse
order in c language
 Question Submitted By :: Srinivas
I also faced this Question!!     Rank Answer Posted By  
 
  Re: write a program to display the array elements in reverse order in c language
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 ?    19 Yes 2 No
Vishnu948923
[No]
 
  Re: write a program to display the array elements in reverse order in c language
Answer
# 2
The above solution is ritee.. :-)

cheers..
 
Is This Answer Correct ?    8 Yes 5 No
Shruti
 
 
 
  Re: write a program to display the array elements in reverse order in c language
Answer
# 3
#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 ?    0 Yes 1 No
Dally
 
  Re: write a program to display the array elements in reverse order in c language
Answer
# 4
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 ?    2 Yes 1 No
Arpit Dhandhania
 
  Re: write a program to display the array elements in reverse order in c language
Answer
# 5
in the above of my answer is correct coz in that i am taking
count =0;
so the array will start from last element.
 
Is This Answer Correct ?    0 Yes 1 No
Dally
 
  Re: write a program to display the array elements in reverse order in c language
Answer
# 6
Answer #2: You have assigned the elements of the array in 
the program itself which by default starts from array index 
0 that is the numbers goes into  the array indices 0 1 2 3 
4 and you have not initialzed or modified the value of i in 
the first loop  which happens to be a garbage or 0 so the 
count goes to infinite. coz a[i] is never '\0'
 Secondly in a numeric array last element in not null 
character it is only in case of character arrays.
Assuming that you have implemented the 1st loop correctly 
and you have the length of array a in count ie = 4 since u 
are starting from 0 then you have initialized i to count 
which makes i = 4.In the second loop the condition is i>=1 
so i=0 is never visited and thus a[0] ir not displayed 
(remember in C array starts from 0 by default).
 
Is This Answer Correct ?    0 Yes 1 No
Arpit Dhandhania
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
Why is conio.h not required when we save a file as .c and use clrscr() or getch() ?  2
two variables are added answer is stored on not for third variable how it is possible?  3
pgm to reverse string using arrays i.e god is love becomes love is god) (assumption:only space is used for seperation of words) no addtional memory used.i.e no temporary arrays can used. Persistent4
2.main { int x,j,k; j=k=6;x=2; x=j*k; printf("%d", x); HCL6
what are the difference between ANSI C and Let Us c and Turbo C LG-Soft1
what is a headerfile?and what will be a program without it explain nan example? Assurgent5
write a C code to reverse a string using a recursive function, without swapping or using an extra memory. Motorola2
6)swap(int x,y) { int temp; temp=x; x=y; y=temp; } main() { int x=2;y=3; swap(x,y); } after calling swap ,what are yhe values x&y?  2
implement general tree using link list Wipro1
how to find turn around time in operating system?  1
how to implement stack operation using singly linked list  1
What is the output for the program given below typedef enum grade{GOOD,BAD,WORST,}BAD; main() { BAD g1; g1=1; printf("%d",g1); } ADITI3
convert 12345 to 54321 withoutusing strig  3
Write a C program that computes the value ex by using the formula ex =1+x/1!+x2/2!+x3+3!+………….  1
write the program for prime numbers? TCS10
write a program to insert an element at the specified position in the given array in c language IBM2
Write a program for the following series: 1*3*5-2*4*6+3*5*7-4*6*8+.................up to nterms Convex-Digital4
i want to know aptitude questions,technical questions  2
c program to add and delete an element from circular queue using array  1
What ios diff. Between %e & %f? Honeywell1
 
For more C 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