In C++, islessgreater() is a predefined function used for mathematical calculations. math.h is the header file required for various mathematical functions.
islessgreater() function is used to check whether the 1st argument given to the function is less than or greater 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 || a<b or not.
Syntax:
bool islessgreater(a, b)
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
int a = 5;
double f1 = nan( "2.0" );
bool result;
result = islessgreater(f1, a);
cout << f1 << " islessgreater than " << a
<< ": " << result;
return 0;
}
|
Output:
nan islessgreater than 5: 0
Example:
- Program:
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
float a, b;
bool result;
a = 10.2;
b = 8.5;
result = islessgreater(a, b);
cout << a << " islessgreater than " << b
<< ": " << result << endl;
int x = 2;
result = islessgreater(x, a);
cout << x << " islessgreater than " << a
<< ": " << result << endl;
a = 8.5;
result = islessgreater(a, b);
cout << a << " islessgreater than " << b
<< ": " << result;
return 0;
}
|
Output:
10.2 islessgreater than 8.5: 1
2 islessgreater than 10.2: 1
8.5 islessgreater than 8.5: 0
Application:
This function can be used in various places, one of them can be in linear search.
CPP
#include <bits/stdc++.h>
using namespace std;
int main()
{
int arr[] = { 5, 2, 8, 3, 4 };
int n = sizeof (arr) / sizeof (arr[0]);
int a = 1;
int flag = 0;
for ( int i = 0; i < n; i++)
{
if (islessgreater(arr[i], a))
{
flag = 1;
}
}
if (flag == 0)
{
cout << a << " is present in array" ;
}
else
{
cout << a << " is not present in array" ;
}
return 0;
}
|
Output:
1 is not present in array
Last Updated :
06 Aug, 2021
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...