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 memcpy() function?
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
What are the loops in c?
What is the equivalent code of the following statement in WHILE LOOP format?
List some basic data types in c?
What is the use of printf() and scanf() functions?
What is the meaning of ?
What is a memory leak? How to avoid it?
Explain the difference between structs and unions in c?
What is the significance of scope resolution operator?
Describe the order of precedence with regards to operators in C.
What is formal argument?
What are the types of assignment statements?
What is a macro in c preprocessor?
Can we access the array using a pointer in c language?