Answer to Question #47756 in C++ for arundhati

Question #47756
c++ program to print array in reverse order.
1
Expert's answer
2014-10-14T00:57:55-0400
#include <iostream>
using namespace std;
int main()
{
int a[5]; // init array
int i; // counter
int n = 5; // count values in array
cout << "Enter 5 number: ";
// dispaly start values
for ( int i = 0; i < n; i++ ) {
cin >> a[i];
}
// reverse array
for ( int i = 0; i < n / 2; i++ ) {
int tmp = a[i];
a[i] = a[ n - i - 1 ];
a[ n - i - 1 ] = tmp;
}
cout << endl; // new string
// dispaly finish values
for ( int i = 0; i < n; i++ ) {
cout << a[i]
<< " ";
}
return 0;
}


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS