Print Friendly and PDF
(Find the Largest) The process of finding the largest number (i.e., the maximum of a group of numbers) is used frequently in computer applications.
(Find the Largest) The process of finding the largest number (i.e., the maximum of a group of numbers) is used frequently in computer applications. 

For example, a program that determines the winner of a sales contest inputs the number of units sold by each salesperson. The salesperson who sells the most units wins the contest. 

Write a C++ program that uses a while statement to determine and print the largest number of 1 0 numbers input by the user. Your program should use three variables, as follows: counter:  A counter to count to 1 0 (i.e., to keep track of how many numbers have been input and to determine when all 10 numbers have been processed). number: The current number input to the program. largest: The largest number found so far.

Solution:

#include < cstdio>
#include < cstdlib>
#include < iostream>
using namespace std;
int main()
{
int counter = 1;
int largest = 0;
int number;
while( counter <= 10)
{
cout << "Enter number: ";
cin >> number;

if( number > largest )
largest = number;
counter++;
}
cout << "Largest number is " << largest << endl;
//for pause
system("PAUSE") ;
return 0;
}

zubairsaif

Zubair saif

A passionate writer who loves to write on new technology and programming

Post A Comment:

1 comments: