write a program to display the array elements in reverse
order in c language
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
what is the stackpointer
in b=6.6/a+(2*a+(3*c)/a*d)/(2/n); which operation will be performed first a) 6.6/a b) 2*a c) 3*c d) 2/n
can we have joblib in a proc ?
#include<stdio.h> void main() { int a,b,c; a=b=c=1; c=++a || ++b && ++c; printf("%d\t%d\t%d",a,b,c); }
how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software
What is a void * in c?
diff. between *p and **p
Write a program for the following series: 1*3*5-2*4*6+3*5*7-4*6*8+.................up to nterms
1. Write a C program to count the number of occurrence of a specific word in the given strings. (for e.g. Find how many times the word “live” comes in the sentence “Dream as if you’ll live forever, live as if you’ll die today ”)
what is the output of the below code? main( ) { printf ( "\nOnly stupids use C?" ) ; display( ) ; } display( ) { printf ( "\nFools too use C!" ) ; main( ) ; }
What is the use of structure padding in c?
There is a number and when the last digit is moved to its first position the resultant number will be 50% higher than the original number.Find the number?