Write a C++ program which prompts the user to enter some numbers and finds the largest number of those entered. Entering 0 should terminate the sequence of numbers and cause the largest number found to be displayed.

Respuesta :

Answer:

Following are the program in c++

#include<iostream> // header file  

using namespace std; // using namespace

int main() // main method

{

  int number, maximum; // variable declaration

  cout << "Entering the number 0 will terminate the program:\n";

  do{

      cin >> number;// read the number

      if(number == 0) // check the condition if number is 0  

      break;

      if(maximum < number) // finding the maximum number

      maximum = number; // assign the number to maximuim variable

  }while(true);

  cout << "The largest of the numbers is : " << maximum << endl;

}

Output:

Entering the number 0 will terminate the program:

19

56

560

6

0

The largest of the numbers is : 560

Explanation:

In this Program we read the number from the user in the do while loop .The loop will iterating untill user is not entered 0 also it checks the condition of finding maximum number in that loop by using if(maximum < number) statement in this condition it store the maximum number in maximum variable .

if user is entered 0 the loop will terminated and Print the maximum number.