Ask Question

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.

+1
Answers (1)
  1. 18 December, 21:25
    0
    Following are the program in c++

    #include / / 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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a C+ + program which prompts the user to enter some numbers and finds the largest number of those entered. Entering 0 should ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers