isgreater() function with example in C++

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

C++ isgreater() function

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

Syntax of isgreater() function:

In C99, it has been implemented as a macro,

    macro isgreater(x, y)

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

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

Parameter(s):

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

Return value:

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

Example:

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

C++ code to demonstrate the example of isgreater() function

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

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

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

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

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

    x = 20.0f;
    y = 10.0f;

    if (isgreater(x, y)) {
        cout << x << " is greater than " << y << endl;
    }
    else {
        cout << x << " is not greater than " << y << endl;
    }

    return 0;
}

Output

isgreater(0.0f, -2.0f): 1
isgreater(10.0f, 20.0f): 0
isgreater(10.0f, 5.0f): 1
isgreater(-10.0f, -20.0f): 1
10 is greater than 5
20 is greater than 10

Reference: C++ isgreater() function







Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.