Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that will read a list of numbers of length size, in which each item is either a positive number or -1, indicating

image text in transcribed
Write a program that will read a list of numbers of length size, in which each item is either a positive number or -1, indicating the end ofthe list sequence. The program will output the length of longest sequence input before a -7 is input. For example if the input is for 9 values and the list is 4 15 9 1 80 2 1 20 1 then the output would be 3 since the longest sequence has size 3. lfthe input is for 12 values and the list is 14 1 -1 9 -1 8 -1 8 9 5 2 -1 then the output would be 4 since the longest sequence has size 4. Prompt the user for the numbers of elements to be input in the sequence using the input and output format below: Enter the list size: [...] Longest sequence = [...] Notes: (1) The [...] should be replaced with the correct values based on the input entered by the user or respective output. (2) Use two variables, one that keeps track of the current sequence length. and another for the longest sequence length. (3) If you see a 1 set the current length to O. (4) Check if the current sequence length is greater than the longest length, if so update the longest. (5) It is possible forthe list of numbers to have multiple sequences of the same size

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

Transport Operations

Authors: Allen Stuart

2nd Edition

978-0470115398, 0470115394

Students also viewed these Programming questions