Home » C++ programming language

fmax() function with example in C++

C++ fmax() function: Here, we are going to learn about the fmax() function with example of cmath header in C++ programming language.
Submitted by IncludeHelp, on April 26, 2019

C++ fmax() function

fmax() function is a library function of cmath header, it is used to find the maximum value of the given numbers, it accepts two number and returns the larger one.

Syntax of fmax() function:

    fmax(x, y);

Parameter(s): x, y – are the numbers to be used to find the larger value.

Return value: double – it returns double value that is the larger value of x and y.

Example:

    Input:
    float x = 20;
    float y = 10;

    Function call:
    fmax(x,y);

    Output:
    20

C++ code to demonstrate the example of fmax() function

// C++ code to demonstrate the example of 
// fmax() function
#include <iostream>
#include <cmath>
using namespace std;

// main() section
int main()
{
    float x;
    float y;
    float result;
    
    //input the numbers
    cout<<"Enter first number : ";
    cin>>x;
    cout<<"Enter second number: ";
    cin>>y;
    
    //finding the maximum number
    result = fmax(x,y);
    cout<<"fmax("<<x<<","<<y<<"): "<<result;
    cout<<endl;
    
    return 0;
}

Output

First run:
Enter first number : 10
Enter second number: -20 
fmax(10,-20): 10 

Second run:
Enter first number : 10
Enter second number: 20
fmax(10,20): 20

Third run:
Enter first number : 123.90
Enter second number: 121.88
fmax(123.9,121.88): 123.9 

Fourth run:
Enter first number : -123.45 
Enter second number: -121.56 
fmax(-123.45,-121.56): -121.56
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT


Top MCQs

Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.