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 (2266)
 C++ interview questions  C++ Interview Questions (1121)
 VC++ interview questions  VC++ Interview Questions (342)
 Delphi interview questions  Delphi Interview Questions (510)
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions (652)
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 ?    244 Yes 117 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 ?    63 Yes 35 No
Arpit Dhandhania
 
 
 
Answer
# 3
The above solution is ritee.. :-)

cheers..
 
Is This Answer Correct ?    86 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 ?    52 Yes 45 No
Dally
 
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 ?    33 Yes 26 No
Pandia
 
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 ?    5 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
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 ?    3 Yes 2 No
Pixie
 
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
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 1 No
Bhikshuk Patel
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
write a program to interchange the value between two variable without using loop   1
how to find turn around time in operating system?   3
void main() { for(; 0 ;) ... { printf("hello"); ... } getch(); }   1
What is Memory leakage ? HCL 2
What is the mean of this statement:: if(int i=0 * i=9) HCL 2
If we give two names then this displays the connection between the two people. It is nothing but flames game   1
What is the difference b/w Structure & Class?   3
Write a C program to multiply tho numbers without using arithmetic operator (+, -, *, /).   1
5. What kind of sorting is this: SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort Accenture 2
what is inline function?   2
How to write in a function declaration and in function call in which the function has 'n' number of varible or arguments?   2
what is a pointer Bank-Of-America 4
 
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