Write a program that gets 5 integer values into an array and then displays the values of the elements of array in reverse order.
So let’s Write Code:
Let’s build logic First:
Algorithm for code:
- Step 1: Start
- Step 2: Declare an array and variable i.
- Step 3: Take inputs from user.
- Step 4: Set Condition for( i =4; i >=0; i–) for reverse order
- Step 5: Print values.
- Step 6: End Program
Code:
Write a program that gets 5 integer values into an array and then displays the values of the elements of array in reverse order.
#include<iostream>
using namespace std;
main()
{
int arr[5], i;
for(i=0; i<=4; i++)
{
cout<<"Enter value in element "<<i<<" ? ";
cin>>arr[i];
}
cout<<"Output in reverse order"<<endl;
for(i=4; i>=0; i--)
{
cout<<arr[i]<<endl;
}
}
Hope You will learn Something. Happy Coding.
Visit my YouTube Channel as Well๐ https://www.youtube.com/watch?v=JuIHQ9cLSEw&list=PLbIhkHxfUIItTdcyCb34uRIrPJbXBndIl&index=4
Click on the below Links for more Programming Exercises:
Conditional Structure Exercises: ๐https://myustaadg.com/category/programming-exercises/conditional-structures-exercises/
Array Exercises: ๐https://myustaadg.com/category/programming-exercises/arrays-exercises/