Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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.
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions