# islessgreater() in C/C++

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

Parameters:

• a, b => These two are the parameters whose value we want to compare.
• Result:

• The function will return the true if (a>b or a<b) else it returns false means when they are equal(a==b).
• Error:

• No error occurs with this function.
• Exception:

• If a or b or both is NaN, then the function raised an exception and return false(0).

 `// CPP code to illustrate ` `// the exception of function ` `#include ` `using` `namespace` `std; ` ` `  `int` `main() ` `{ ` `    ``// Take any values ` `    ``int` `a = 5; ` `    ``double` `f1 = nan(``"2.0"``); ` `    ``bool` `result; ` ` `  `    ``// Since f1 value is NaN so ` `    ``// with any value of a, the function ` `    ``// always return false(0) ` `    ``result = islessgreater(f1, a); ` `    ``cout << f1 << ``" islessgreater than "` `<< a ` `         ``<< ``": "` `<< result; ` ` `  `    ``return` `0; ` `} `

Output:

```nan islessgreater than 5: 0
```

Example:

• Program:

 `// CPP code to illustrate ` `// the use of islessgreater function ` `#include ` `using` `namespace` `std; ` ` `  `int` `main() ` `{ ` `    ``// Take two any values ` `    ``float` `a, b; ` `    ``bool` `result; ` `    ``a = 10.2; ` `    ``b = 8.5; ` ` `  `    ``// Since 'a' is not less than 'b' ` `    ``// but greater than 'b' so answer ` `    ``// is true(1) ` `    ``result = islessgreater(a, b); ` `    ``cout << a << ``" islessgreater than "` `<< b ` `         ``<< ``": "` `<< result << endl; ` ` `  `    ``int` `x = 2; ` ` `  `    ``// Since 'x' is not greater than 'b' ` `    ``// but less than 'a' vaiable so answer ` `    ``// is true(1) ` `    ``result = islessgreater(x, a); ` `    ``cout << x << ``" islessgreater than "` `<< a ` `         ``<< ``": "` `<< result << endl; ` ` `  `    ``a = 8.5; ` ` `  `    ``// Since value of 'a' and 'b' are ` `    ``// equal so answer is false(0) ` `    ``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 code to illustrate the ` `// use of islessgreater function ` `#include ` `using` `namespace` `std; ` ` `  `int` `main() ` `{ ` `    ``// taking inputs ` `    ``int` `arr[] = { 5, 2, 8, 3, 4 }; ` `    ``int` `n = ``sizeof``(arr) / ``sizeof``(arr[0]); ` ` `  `    ``// Lets we want to search for 1 in ` `    ``// the arr array ` `    ``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
```

GeeksforGeeks has prepared a complete interview preparation course with premium videos, theory, practice problems, TA support and many more features. Please refer Placement 100 for details

My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

Article Tags :
Practice Tags :

Be the First to upvote.

Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.