63 821
Assignments Done
99,4%
Successfully Done
In August 2018

Answer to Question #47756 in C++ for arundhati

Question #47756
c++ program to print array in reverse order.
Expert's answer
#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 first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions