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

I have an array of 100 elements, each of which is a random integer. I want to know which of the elements: a) are multiples of 2 b) are multiples of 2 AND 5 c) have a remainder of 3 when divided by 7

1 Answers  


Write a function stroverlap that takes (at least) two strings, and concatenates them, but does not duplicate any overlap. You only need to worry about overlaps between the end of the first string and the beginning of the second string. Examples: batman, manonthemoon = batmanonthemoon batmmamaman, mamamanonthemoon = batmmamamanonthemoon bat, man = batman batman, batman = batman batman, menonthemoon = batmanmenonthemoon

0 Answers   HCL,


What is the difference between functions abs() and fabs()?

0 Answers  


what is the difference between c and java?

1 Answers  


What are the 5 elements of structure?

0 Answers  


Write a program to reverse a linked list in c.

0 Answers   DELL, HAL,


Distinguish between actual and formal arguments.

0 Answers  


i = 25;switch (i) {case 25: printf("The value is 25 ");case 30: printf("The value is 30 "); When the above statements are executed the output will be : a) The value is 25 b) The value is 30 c) The value is 25 The value is 30 d) none

0 Answers  


Why enum is used in c?

0 Answers  


What is character set?

0 Answers  


Is printf a keyword?

0 Answers  


Do you know what is the purpose of 'extern' keyword in a function declaration?

0 Answers  


Categories