C++ fmin()
Published Oct 26, 2022Updated Dec 21, 2022
The fmin() function returns the smaller of two arguments.
Syntax
fmin(x, y)
The parameters x and y are usually a numeric data type ranging from negative to positive INFINITY. If one of the parameters is NaN, then the other parameter is returned.
Example
The following example uses the fmin() function to find the smaller value between 3 and 5:
#include <iostream>#include <cmath>int main() {double x = 3;double y = 5;double result;result = fmin(x, y);std::cout << "The smaller value between " << x << " and " << y << " is " << result << "\n";}
This produces the following output:
The smaller value between 3 and 5 is 3
Codebyte Example
The following example returns the smaller value between -32.123 and -32.231:
Learn C++ on Codecademy
- Looking for an introduction to the theory behind programming? Master Python while learning data structures, algorithms, and more!
- Includes 6 Courses
- With Professional Certification
- Beginner Friendly.75 hours
- Learn C++ — a versatile programming language that’s important for developing software, games, databases, and more.
- Beginner Friendly.11 hours