write a program to display the array elements in reverse
order in c language
Answer Posted / 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 View All Answers
What is hashing in c language?
Explain how can you determine the size of an allocated portion of memory?
What is the size of a union variable?
How do you use a pointer to a function?
What is the difference between functions abs() and fabs()?
Can you please explain the difference between malloc() and calloc() function?
What does c value mean?
How do I convert a string to all upper or lower case?
A global variable when referred to in another file is declared as this a) local variable b) external variable c) constant d) pointers
What does %p mean c?
What is the purpose of macro in C language?
State the difference between x3 and x[3].
How can I insert or delete a line (or record) in the middle of a file?
How do I get a null pointer in my programs?
How important is structure in life?