•Write a c++ program that reads 15 integers and stores in an array. Print the array in reverse order.
Answers
Answered by
7
Printing Array in Reverse - C++
We declare a size 15 array named as follows:
Next, we take in user input of the 15 values using .
Array elements are accessed by their index. If the loop variable runs from 0 to 14, then we can print the array in reverse by using .
ReverseArray.cpp
#include <iostream>
using namespace std;
int main() {
int integerArray[15]; //Create integer array of size 15
for(int i = 0; i < 15; i++) {
cout << "Enter Integer [" << i+1 << "]: ";
cin >> integerArray[i]; //Take user input
}
cout << "The array in reverse order:" << endl;
for(int i = 0; i < 15; i++) { //Print array in reverse
cout << integerArray[15-i-1] << endl;
}
return 0;
}
Attachments:
Similar questions