×

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

fmin() function with example in C++

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

C++ fmin() function

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

Syntax

Syntax of fmin() function:

fmin(x, y);

Parameter(s)

x, y – are the numbers to be used to find the smaller value.

Return value

double – it returns double value that is the smaller value of x and y.

Sample Input and Output

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

Function call:
fmin(x,y);

Output:
10

Example

// C++ code to demonstrate the example of 
// fmin() 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 minimum number
    result = fmin(x,y);
    cout<<"fmin("<<x<<","<<y<<"): "<<result;
    cout<<endl;
    
    return 0;
}

Output

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

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

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

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


Comments and Discussions!

Load comments ↻





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