write a program to display the array elements in reverse
order in c language

Answers were Sorted based on User's Feedback



write a program to display the array elements in reverse order in c language..

Answer / vishnu948923

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 ?    258 Yes 125 No

write a program to display the array elements in reverse order in c language..

Answer / shruti

The above solution is ritee.. :-)

cheers..

Is This Answer Correct ?    93 Yes 64 No

write a program to display the array elements in reverse order in c language..

Answer / arpit dhandhania

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 ?    65 Yes 39 No

write a program to display the array elements in reverse order in c language..

Answer / pandia

#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 28 No

write a program to display the array elements in reverse order in c language..

Answer / dally

#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 48 No

write a program to display the array elements in reverse order in c language..

Answer / prajot chougale

#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 ?    5 Yes 4 No

write a program to display the array elements in reverse order in c language..

Answer / tej

#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 ?    7 Yes 6 No

write a program to display the array elements in reverse order in c language..

Answer / siraj-ud-doulla

#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 ?    3 Yes 2 No

write a program to display the array elements in reverse order in c language..

Answer / pixie

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 5 No

write a program to display the array elements in reverse order in c language..

Answer / s r samanta

#include<iostream>
using namespace std;
int main()
{
int n, c, j, temp, a[100];

cout<<"Enter the number of elements in array\n";
cin>>n;

cout<<"Enter the array elements\n";

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

if( n%2 == 0 )
c = n/2 - 1;
else
c = n/2;

for ( j = 0 ; j < c ; j++ )
{
temp = a[j];
a[j] = a[n -j - 1];
a[n-j-1] = temp;
}


cout<<"Reverse arry\n";
for( c = 0 ; c < n ; c++ )
cout<<"\n"<< a[c];


return 0;
}

Is This Answer Correct ?    1 Yes 3 No

Post New Answer

More C Interview Questions

f(char *p) { p=(char *)malloc(sizeof(6)); strcpy(p,"HELLO"); } main() { char *p="BYE"; f(p) printf("%s",p); } what is the output?

9 Answers   Hughes, Tech Mahindra,


Which is an example of a structural homology?

0 Answers  


What is external variable in c?

0 Answers  


Write a program which returns the first non repetitive character in the string?

0 Answers   Expedia,


What is pointers in c with example?

0 Answers  






How do you print an address?

0 Answers   TCS,


Is reference used in C?

1 Answers  


char ch=10;printf("%d",ch);what is the output

14 Answers   Accenture,


Explain two-dimensional array.

0 Answers  


What is && in c programming?

0 Answers  


#include<stdio.h> void main() { int a [5]; for (i=0; i<=4; i++) printf(ā€œ%dā€ ,a[i]); }

8 Answers  


what is unsigened char and what is the difference from char

2 Answers  


Categories