Home »
C++ programming language
isless() Function with Example in C++
C++ isless() function: Here, we are going to learn about the isless() function with example of cmath header in C++ programming language?
Submitted by IncludeHelp, on May 17, 2020
C++ isless() function
isless() function is a library function of cmath header, it is used to check whether the given first value is less than the second value. It accepts two values (float, double or long double) and returns 1 if the first value is less than the second value; 0, otherwise.
Syntax
Syntax of isless() function:
In C99, it has been implemented as a macro,
macro isless(x, y)
Syntax
In C++11, it has been implemented as a function,
bool isless (float x , float y);
bool isless (double x , double y);
bool isless (long double x, long double y);
Parameter(s)
- x, y – represent the two values to be checked whether x is less than the y.
Return value
The returns type of this function is bool, it returns 1 if x is less than y; 0, otherwise.
Sample Input and Output
Input:
float x = 5.0f;
float y = 15.0f;
Function call:
isless(x, y);
Output:
1
Example
C++ code to demonstrate the example of isless() function:
// C++ code to demonstrate the example of
// isless() function
#include <iostream>
#include <cmath>
using namespace std;
int main()
{
cout << "isless(0.0f, -2.0f) : " << isless(0.0f, -2.0f) << endl;
cout << "isless(10.0f, 20.0f) : " << isless(10.0f, 20.0f) << endl;
cout << "isless(10.0f, 5.0f) : " << isless(10.0f, 5.0f) << endl;
cout << "isless(-10.0f, -20.0f): " << isless(-10.0f, -20.0f) << endl;
float x = 10.0f;
float y = 5.0f;
// checking using the condition
if (isless(x, y)) {
cout << x << " is less than " << y << endl;
}
else {
cout << x << " is not less than " << y << endl;
}
x = 9.0f;
y = 10.0f;
if (isless(x, y)) {
cout << x << " is less than " << y << endl;
}
else {
cout << x << " is not less than " << y << endl;
}
return 0;
}
Output
isless(0.0f, -2.0f) : 0
isless(10.0f, 20.0f) : 1
isless(10.0f, 5.0f) : 0
isless(-10.0f, -20.0f): 0
10 is not less than 5
9 is less than 10
Reference: C++ isless() function