Computer Science, asked by irascyed, 9 months ago

•Write a c++ program that reads 15 integers and stores in an array. Print the array in reverse order.

Answers

Answered by QGP
7

Printing Array in Reverse - C++

We declare a size 15 array named \texttt{integerList} as follows:

\texttt{int integerList[15];}

Next, we take in user input of the 15 values using \tt cin.

Array elements are accessed by their index. If the loop variable \tt i runs from 0 to 14, then we can print the array in reverse by using \texttt{15-i-1} .

 \rule{300}{1}

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