Question: C + + Q 2 . Loop and array Write a program to find the maximum number among the right - hand side of an
CQ Loop and array
Write a program to find the maximum number among the righthand 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 if the next smaller elements don't exist, at the same position in the output array.
For example: the input array is
We consider the second element The elements that are at the righthand side of and
smaller than it are Then the maximum value among them is Therefore, at the
position of in the output array, we should assign the value of
With the rule, we can get that the output array of should be
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.
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
