Question: C + + Q 2 . Loop and array Write a program to find the maximum number among the right - hand side of an

C++Q2. Loop and array
Write a program to find the maximum number among the right-hand side of an element that
is smaller than the current element for each element in an integer array. The output of the
program is another integer array created by yourself. Assign the value of the maximum value
or -1, if the next smaller elements don't exist, at the same position in the output array.
For example: the input array is 5,6,3,4,1,2.
We consider the second element 6. The elements that are at the right-hand side of 6 and
smaller than it are 3,4,1,2. Then the maximum value among them is 4. Therefore, at the
position of 2 in the output array, we should assign the value of 4.
With the rule, we can get that the output array of 5,6,3,4,1,2 should be 4,4,2,2,-1,-1.
The program asks the user to input the size of the array first, followed by every element in the
array. Every element of the array is an integer.
Expected Outcomes:Cc
 C++Q2. Loop and array Write a program to find the maximum

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!