×

C++ Tutorial

C++ Data types

C++ Operators & Keywords

C++ Conditional Statements

C++ Functions

C++ 'this' Pointer, References

C++ Class & Objects

C++ Constructors & Destructors

C++ Operator overloading

C++ 11 (Advance C++)

C++ Preparation

C++ Header Files & Functionsr

Data Structure with C++

C++ - Miscellaneous

C++ Programs

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

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.

Sample Input and Output

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

Function call:
fmax(x,y);

Output:
20

Example

// 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


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.