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 is memcpy() function?

615


how to print electricity bill according to following charges first 100 units -1rs per unit for next 200 units-1.50 rs per unit without using conditions

2714


What are the loops in c?

589


What is the equivalent code of the following statement in WHILE LOOP format?

757


List some basic data types in c?

552






What is the use of printf() and scanf() functions?

619


What is the meaning of ?

602


What is a memory leak? How to avoid it?

561


Explain the difference between structs and unions in c?

565


What is the significance of scope resolution operator?

845


Describe the order of precedence with regards to operators in C.

628


What is formal argument?

638


What are the types of assignment statements?

622


What is a macro in c preprocessor?

616


Can we access the array using a pointer in c language?

554