Final answer:
A Python program reads integers until a negative is entered, tracking and outputting the largest integer. The program uses a while loop and if statements.
Step-by-step explanation:
Program to Find the Largest Integer
The program you need to write should read integers from the user until a negative integer is entered. During this process, it should compare each entered integer with the current largest integer and update this largest integer if a larger one is found. Once a negative integer is entered, the program should terminate and output the largest integer encountered. Here is a Python example:
largest = -1
while True:
number = int(input('Enter an integer (negative to quit): '))
if number < 0:
break
if number > largest:
largest = number
print('The largest integer is:', largest)
This code initializes largest to -1 and uses a while loop to read integers until a negative number is inputted. The if statement checks for a negative number to terminate the loop, and another if statement checks whether the entered number is greater than largest to update its value. Finally, it prints the largest number.