Print Friendly and PDF
(Find the Two Largest Numbers) Using an approach similar to that in Exercise 4.1 7, find the two largest values among the 1 0 numbers. [Note: You must input each number only once.] Solution:
(Find the Two Largest Numbers) Using an approach similar to that in Exercise 4.1 7, find the two largest values among the 1 0 numbers. [Note: You must input each number only once.]

Solution:

#include < cstdio>
#include < cstdlib>
#include < iostream>
using namespace std;
int main()
{
//инициализация переменных
int counter = 1;
int largest = 0;
int largest2 = 0;
int number;
//выполнение цикла со счетчиком
while( counter <= 10)
{
cout << "Enter number: ";
cin >> number;
if( (number > largest) &amp; &amp; (number > largest2) )
{
largest = largest2;
largest2 = number;

}

else 
if( (number > largest) &amp; &amp; (number < largest2) )
{
largest = number;
}
cout << "Largest two numbers are " << largest << " and " << largest2 << endl;
counter++;
}
cout << "Largest two numbers are " << largest << " and " << largest2 << 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:

0 comments: