Final answer:
To write a program that takes any number of non-negative integers as input and outputs the average and max, you can use a loop to continuously take input numbers until a negative number is entered.
Step-by-step explanation:
To write a program that takes any number of non-negative integers as input and outputs the average and max, you can use a loop to continuously take input numbers until a negative number is entered. Within the loop, keep track of the sum of the numbers and the maximum number encountered. After the loop ends, calculate the average by dividing the sum by the number of inputs.
Here is an example implementation in Python:
count = 0
sum = 0
max = None
while True:
num = int(input())
if num < 0:
break
count += 1
sum += num
if max is None or num > max:
max = num
average = sum / count
print('Average:', average)
print('Max:', max)
When this program is run with the input 15 20 0 5 -1, it will output:
Average: 10.0
Max: 20