In: Computer Science
Create a Visual Studio console project (c++) containing a main() program that declares a const int NUM_VALUES denoting the array size. Then declare an int array with NUM_VALUES entries. Using a for loop, prompt for the values that are stored in the array as follows: "Enter NUM_VALUES integers separated by blanks:" , where NUM_VALUES is replaced with the array size. Then use another for loop to print the array entries in reverse order separated by blanks on a single line as follows: "The array contents in reverse order: " Your code should work for any array size by only changing the NUM_VALUES declaration.
Explanation:
Here is the code which sets the constant value NUM_VALUES to some integer value.
Then values are asked for the array to store the values.
Then that array is printed in the reverse direction.
Code:
#include <iostream>
using namespace std;
int main()
{
const int NUM_VALUES = 5;
int arr[NUM_VALUES];
cout<<"Enter "<<NUM_VALUES<<" integers separated
by blanks: ";
for (int i = 0; i < NUM_VALUES; i++) {
cin>>arr[i];
}
cout<<"The array contents in reverse order: ";
for (int i = NUM_VALUES-1; i >=0; i--) {
cout<<arr[i]<<" ";
}
return 0;
}
Output:
PLEASE UPVOTE IF YOU FOUND THIS HELPFUL!
PLEASE COMMENT IF YOU NEED ANY HELP!