In C++, isless() is a predefined function used for mathematical calculations. math.h is the header file required for various mathematical functions.
isless() function used to check whether the 1st argument given to the function is less than the 2nd argument given to the function or not. Means if a is the 1st argument and b is the 2nd argument then it check whether a<b or not.
Syntax:
bool isless(a, b)
Time Complexity: O(1)
Auxiliary Space: O(1)
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a = 5;
double b = nan( "1" );
bool result;
result = isless(a, b);
cout << a << " isless than " << b
<< ": " << result;
return 0;
}
|
Output:
5 isless than nan: 0
Example:
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a, b;
bool result;
a = 5;
b = 8;
result = isless(a, b);
cout << a << " isless than " << b
<< ": " << result << endl;
char x = 'a' ;
result = isless(x, b);
cout << x << " isless than " << b
<< ": " << result;
return 0;
}
|
Output:
5 isless than 8: 1
a isless than 8: 0
Note: Using this function you can compare any data type with any other data type as well.
Application
There are variety of applications where we can use isless() function to compare two values like to use in while loop to print the first 9 natural number.
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
int i = 1;
while (isless(i, 10)) {
cout << i << " " ;
i++;
}
return 0;
}
|
Output:
1 2 3 4 5 6 7 8 9
Last Updated :
20 Feb, 2023
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...