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


Please Help Members By Posting Answers For Below Questions

What does c value mean?

631


Can main () be called recursively?

633


Why is structure important for a child?

605


write a program to create a sparse matrix using dynamic memory allocation.

4375


Describe how arrays can be passed to a user defined function

787






What are the types of macro formats?

613


What are the ways to a null pointer can use in c programming language?

592


A c program to display count values from 0 to 100 and flash each digit for a secong.reset the counter after it reaches 100.use for loop,. pls guys hepl me.. :(

1745


Can two or more operators such as and be combined in a single line of program code?

813


What is the difference between char array and char pointer?

527


What is the function of multilevel pointer in c?

672


How are structure passing and returning implemented?

594


What is difference between structure and union in c programming?

573


What is wrong with this program statement?

610


How many bytes is a struct in c?

728