Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

c++ 5. (20%) (Counting Up and Down Segments] Given a sequence of positive numbers, we can know whether the values of these numbers becomes larger

c++
image text in transcribed
5. (20%) (Counting Up and Down Segments] Given a sequence of positive numbers, we can know whether the values of these numbers becomes larger and larger (including the same value), or smaller and smaller (including the same value), or change the direction. For instance, given the sequence (1, 2, 3, 3), we know that the sequence goes up or stay unchanged without changing the direction (that is, we count that there is 1 up-segment); given the sequence (8, 4, 2, 1, 0), we know the sequence goes down without changing the direction (that is, there is 1 down-segment); and given the sequence (3, 44,0, 34, 3, 4, 5, 31, 40), we can find out that 3->44 goes up, then 44->0 goes down, and then 0->34 goes up, and then 34->3 goes down, and finally 3->4->5->31-340 goes up. So, for these three exemplified sequences, there are 1 up- segment, 1 down-segment, and 3 up-segments plus 2 down-segments, respectively. Write a program to accept a sequence of positive number ended with the value of -1, and the program will output the total number of up-segments and total number of down-segments in the inputted sequence of positive numbers. Sample 1 Input a sequence of numbers (ended with -1): No. of Up Movement is: No. of Down Movement is: Sample 2 Input a sequence of numbers (ended with -1): 1 2 3 4 3 21.1 No. of Up Movement is: 1 No. of Down Movement is: 1 Sample 3 Input a sequence of numbers (ended with -1): 3. 4 4 2 9 6.34-1 No. of Up Movement is: 3 No. of Down Movement is: 3 Sample 4 Input a sequence of numbers (ended with - 1) 1 4682 97 6 5 4 3 27 8 9 No. of Up Movement is: 8 No. of Down Movement is: 7 Samples Input a sequence of numbers (ended with - 1): 1114 4 4 No. of Up Movement is: 1 No. of Down Movement is: e

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

Structured Search For Big Data From Keywords To Key-objects

Authors: Mikhail Gilula

1st Edition

012804652X, 9780128046524

More Books

Students also viewed these Databases questions