EXAMPLE :
If the numbers are 4, 43, 6.7, 34, 6, -9, 0 , 22
The second largest value is 34.
Example: If the numbers are 4, 43, 6.7, 34, 6, -9, 0 ,43, 22
The second largest value, ignoring the duplicate 43, is 34
If the numbers input are 1 1 1 1 1 1
the second largest value is 1
What if the user enters only one number?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include <iostream>
using namespace std;
int main()
{
char r;
double number,largest,second_largest;
cout << "enter the numbers : " ;
cin >> largest;
cout <<" Do you want to continue (Y) or (N)" ;
cin >> r;
while(r=='y')
{
cin>> number;
if (number >= largest)
{
second_largest = largest;
largest = number;}
else if (number >= second_largest)
{
second_largest = number;}
cout << "Do you want to continue (Y) or (N) " ;
cin >> r;
}
cout <<"secondlargest"<<second_largest;
return 0;
}
|
ı wrote something but ı can't find the numbers because they repeat