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 |
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
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
What is the difference between functions abs() and fabs()?
what is the difference between c and java?
What are the 5 elements of structure?
Write a program to reverse a linked list in c.
Distinguish between actual and formal arguments.
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
Why enum is used in c?
What is character set?
Is printf a keyword?
Do you know what is the purpose of 'extern' keyword in a function declaration?