Answer:
Here's an example program in Python that takes any number of non-negative integers as input, calculates the maximum and average, and terminates when a negative integer is entered.
numbers = []
while True:
num = int(input("Enter a non-negative integer (enter a negative integer to finish): "))
if num < 0:
break
numbers.append(num)
if len(numbers) > 0:
maximum = max(numbers)
average = sum(numbers) / len(numbers)
print("Maximum:", maximum)
print("Average:", average)
Step-by-step explanation:
In this program, we initialize an empty list called numbers to store the non-negative integers provided by the user. We use a while loop to repeatedly ask the user for input until a negative integer is entered. Each non-negative integer is appended to the numbers list.
After exiting the loop, we check if there is at least one non-negative integer in the list. If so, we calculate the maximum using the max() function and the average by summing the numbers and dividing by the length of the list.
Finally, we display the maximum and average values using the print() function.
You can run this program and enter non-negative integers one by one. Once you enter a negative integer, the program will calculate and display the maximum and average based on the provided input.