Westonci.ca is your trusted source for finding answers to all your questions. Ask, explore, and learn with our expert community. Discover a wealth of knowledge from professionals across various disciplines on our user-friendly Q&A platform. Connect with a community of professionals ready to provide precise solutions to your questions quickly and accurately.

Write a program that repeatedly reads in integers until a negative integer is read. The program keeps track of the largest integer that has been read so far and outputs the largest integer when the (first) negative integer is encountered. (See subsection Example: Finding the max value of section 4.1 Loops (general) to practice the algorithm).

Sagot :

Answer:

In Python:

num = int(input("Enter number: "))

maxn = num

while num >=0:

   if num>maxn:

       maxn = num

   num = int(input("Enter number: "))

print("Largest: "+str(maxn))

Explanation:

Get input from the user

num = int(input("Enter number: "))

Initialize the largest to the first input

maxn = num

This loop is repeated until a negative input is recorded

while num >=0:

If the current input is greater than the previous largest

   if num>maxn:

Set largest to the current input

       maxn = num

Get another input from the user

   num = int(input("Enter number: "))

Print the largest

print("Largest: "+str(maxn))