Answer:
Following are the code to this question:
#include <iostream>// header file
using namespace std;
int main()//main method
{
int arr1[]= {10, 15, 19, 23, 26, 29, 31, 34, 38};//defining array of integer values
int i;//defining integer variable
cout<<" Array from first to last: ";//print message
for(i=0;i<9;i++)//use for loop to print array
{
cout<<arr1[i]<<" ";//print array value
}
cout<<"\n Array from last to first : ";//print message
for(i=9-1;i>=0;i--)//defining for loop to print array in reverse order
{
cout<<arr1[i]<<" ";//print array
}
return 0;
}
Output:
Array from first to last: 10 15 19 23 26 29 31 34 38
Array from last to first : 38 34 31 29 26 23 19 15 10
Explanation:
In the above-given code, an array "arr1" of an integer value is declared, that stores 9 elements, in the next step, an integer variable i is declared, that uses two for loop to print the value in the given order.
- In the first for loop, it starts from 0 and ends when its value less than 9, and prints the array value.
- In the second for loop, it starts from 9 and ends when the index value equal to 0, and prints the array value in reverse order.