/*In the Following code, we are finding maximum number from given three numbers, for this just need to use the ” if ” conditional statement & use the ” < ” or ” > ” operators to check out the max. number or min. number. This is the C++ program to find largest of 3 given numbers*/
// program to find largest of 3 numbers entered by user.
#include <iostream>
#include<stdlib.h> //For system("pause") function
using namespace std;
double maximum( double x, double y, double z ) //Function Definition
{
double max = x;
if ( y > max ) // if y is larger,
max = y;
if ( z > max ) // if z is larger,
max = z;
return max; // max is largest value
} // end function maximum
int main()
{
double number1;
double number2;
double number3;
cout << "Enter three floating-point numbers: ";
cin >> number1 >> number2 >> number3; // number input
cout << "Maximum is: " << maximum( number1, number2, number3 ) << endl;
using namespace std;
double maximum( double x, double y, double z ) //Function Definition
{
double max = x;
if ( y > max ) // if y is larger,
max = y;
if ( z > max ) // if z is larger,
max = z;
return max; // max is largest value
} // end function maximum
int main()
{
double number1;
double number2;
double number3;
cout << "Enter three floating-point numbers: ";
cin >> number1 >> number2 >> number3; // number input
cout << "Maximum is: " << maximum( number1, number2, number3 ) << endl;
system("pause");
return 0; // indicates successful termination
}
return 0; // indicates successful termination
}
ScreenShots:
C++ Program to find largest of 3 numbers |
0 comments:
Post a Comment