×

C++ Tutorial

C++ Data types

C++ Operators & Keywords

C++ Conditional Statements

C++ Functions

C++ 'this' Pointer, References

C++ Class & Objects

C++ Constructors & Destructors

C++ Operator overloading

C++ 11 (Advance C++)

C++ Preparation

C++ Header Files & Functionsr

Data Structure with C++

C++ - Miscellaneous

C++ Programs

islessgreater() Function with Example in C++

C++ islessgreater() function: Here, we are going to learn about the islessgreater() function with example of cmath header in C++ programming language?
Submitted by IncludeHelp, on May 17, 2020

C++ islessgreater() function

islessgreater() function is a library function of cmath header, it is used to check whether the given first value is either less than or greater than the second value. It accepts two values (float, double or long double) and returns 1 if the first value is either less than or greater than the second value; 0, otherwise.

Syntax

Syntax of islessgreater() function:

In C99, it has been implemented as a macro,

macro islessgreater(x, y)

Syntax

In C++11, it has been implemented as a function,

bool islessgreater (float x      , float y);
bool islessgreater (double x     , double y);
bool islessgreater (long double x, long double y);

Parameter(s)

  • x, y – represent the two values to be checked whether x is either less than or greater than the y.

Return value

The returns type of this function is bool, it returns 1 if x is either less than or greater than y; 0, otherwise.

Sample Input and Output

Input:
float x = 10.0f;
float y = 15.0f;
    
Function call:
islessgreater(x, y);
    
Output:
1

Input:
float x = 15.0f;
float y = 10.0f;
    
Function call:
islessgreater(x, y);
    
Output:
1

Input:
float x = 10.0f;
float y = 10.0f;
    
Function call:
islessgreater(x, y);
    
Output:
0

Example

C++ code to demonstrate the example of islessgreater() function:

// C++ code to demonstrate the example of
// islessgreater() function

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
    cout << "islessgreater(-5.0f, -2.0f)  : " << islessgreater(-5.0f, -2.0f) << endl;
    cout << "islessgreater(10.0f, 20.0f)  : " << islessgreater(10.0f, 20.0f) << endl;
    cout << "islessgreater(10.0f, 10.0f)  : " << islessgreater(10.0f, 10.0f) << endl;
    cout << "islessgreater(-10.0f, -20.0f): " << islessgreater(-10.0f, -20.0f) << endl;

    float x = 10.0f;
    float y = 5.0f;

    // checking using the condition
    if (islessgreater(x, y)) {
        cout << x << " is either less than or greater than " << y << endl;
    }
    else {
        cout << x << " is not either less than or greater than " << y << endl;
    }

    x = 10.0f;
    y = 15.0f;

    if (islessgreater(x, y)) {
        cout << x << " is either less than or greater than " << y << endl;
    }
    else {
        cout << x << " is not either less than or greater than " << y << endl;
    }

    return 0;
}

Output

islessgreater(-5.0f, -2.0f)  : 1
islessgreater(10.0f, 20.0f)  : 1
islessgreater(10.0f, 10.0f)  : 0
islessgreater(-10.0f, -20.0f): 1
10 is either less than or greater than 5
10 is either less than or greater than 15

Reference: C++ islessgreater() function



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.