Complete your code for this task within the function task5 1
Complete your code for this task within the function task5().
1. You need to implement code to output the following line to the screen:
–- Task 5 –-
2. In the main function display the following message: Enter a list of space separated numbers, terminated with -1:
3. Add statements to the main function so that the program reads in a whole number integer from the keyboard and stores it in a variable named input.
4. Encapsulate the capture of the number within a loop that will continue processing numbers until it finds -1. Once the loop terminates display the following information: The largest number is input The occurrence count of the largest number is input where input is the last value assigned to input.
5. Create two variables max and count. max stores the current max number and count stores its number of occurrences. Initially, assign the first number captured to max and 1 to count. Compare each subsequent number with max. If the number is greater than max, assign it to max and reset count to 1. If the number is equal to max, increment count by 1. Use the values stored in max and count to correctly complete the output of your program. Here are sample runs of the program:
Sample 1 :
Task 5 ( should look like these samples below)
Enter a list of space separated numbers , terminated with 1:
3 5 2 5 5 5 1
The largest number is 5
The occurrence count of the largest number i s 4
Sample 2 :
Task 5
Enter a list of space separated numbers , terminated with 1:
3654245455 1 The largest number is 6
The occurrence count of the largest number is 1
Solution
Please find the required program along with its output. Please see the comments against each line to understand the step.
--------------------------
OUTPUT:
–- Task 5 –-
Enter a list of space separated numbers, terminated with -1:
3 5 2 5 5 5 -1
The largest number is 5
The occurrence count of the largest number is 4
