Sep 17, 2013

C++ program to find the largest value among any four numbers

Unknown | 11:14 AM |
Today I am going to tell you how to find the largest value among any four numbers with a simple C++ program. You can also see how to find the largest value of any three numbers






Anyway, the C++ program code is bellow:


// A C++ program to find the largest value among any four numbers
#include <iostream.h>
void main(void)
{
 float a,b,c,d;
 cout << "Enter any four numbers \n";
 cin >>a >>b >>c >>d;
 if (a > b) {
if (a > c) {
if (a > d)
cout <<"Largest value" << a << endl;
else cout <<"Largest value" << d << endl;
}
else {
if (c > d)
cout <<"Largest value" << c << endl;
else cout <<"Largest value" << d << endl;
}
} // end of outer if part
else {
if (b > c) {
if (b > d)
cout <<"Largest value" << b << endl;
else cout <<"Largest value" << d << endl;
}
else {
if (c > d)
cout <<"Largest value" << c << endl;
else cout <<"Largest value" << d << endl;
}
} // end of outer else part
} // end of main program

Output:


Enter any four numbers 
10   40    50    70 
Largest value 70

Thanks! 

No comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More

Search