# 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 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.

Example:

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

Function call:
fmin(x,y);

Output:
10
```

### C++ code to demonstrate the example of fmin() function

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

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