Open In App

isgreaterequal() in C/C++

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Share
Report issue
Report

In C++, isgreaterequal() is a predefined function used for mathematical calculations. math.h is the header file required for various mathematical functions. isgreaterequal() function used to check whether the 1st argument given to the function is greater than or equal to 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 isgreaterequal(a, b)
  • If a or b or both is NaN then the function raised an exception and return false(0). 

Time Complexity: O(1)

Auxiliary Space: O(1)

CPP




// CPP code to illustrate
// the exception of function
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    // Take any values
    float a = 5.5;
    double f1 = nan("1");
    bool result;
 
    // Since f1 value is NaN so
    // with any value of a, the function
    // always return false(0)
    result = isgreaterequal(a, f1);
    cout << a << " isgreaterequal " << f1
        << ": " << result;
 
    return 0;
}


  • Output:
5.5 isgreaterequal nan: 0

Program 1:

CPP




// CPP code to illustrate
// the use of isgreaterequal function
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    // Take two any values
    int a, b;
    bool result;
    a = 5;
    b = 8;
 
    // Since 'a' is not greater
    // than equal to 'b' so answer
    // is false(0)
    result = isgreaterequal(a, b);
    cout << a << " isgreaterequal to " << b
        << ": " << result << endl;
 
    a = 8;
    b = 5;
 
    // Since 'a' is greater
    // than 'b' so answer
    // is true(1)
    result = isgreaterequal(a, b);
    cout << a << " isgreaterequal to " << b
        << ": " << result;
 
    return 0;
}


  • Output:
5 isgreaterequal to 8: 0
8 isgreaterequal to 5: 1
  • Program 2: 

CPP




// CPP code to illustrate
// the use of isgreaterequal function
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    // Take two any values
    bool result;
    float a = 80.23;
    int b = 82;
 
    // Since 'a' is not greater
    // than equal to 'b' so answer
    // is false(0)
    result = isgreaterequal(a, b);
    cout << a << " isgreaterequal to " << b
        << ": " << result << endl;
 
    char x = 'b';
 
    // Since 'b' ascii value is greater
    // than variable a so answer
    // is true(1)
    result = isgreaterequal(x, a);
    cout << x << " isgreaterequal to " << a
        << ": " << result;
 
    return 0;
}


  • Output:
80.23 isgreaterequal to 82: 0
b isgreaterequal to 80.23: 1

Application

There are variety of applications where we can use isgreaterequal() function to compare two values like to use in for loop to print table of any number say 12. 

CPP




// CPP code to illustrate
// the use of isgreaterequal function
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
 
    for (int i = 1;
        isgreaterequal(10, i);
        i++) {
        cout << "12 x " << i << " = "
            << 12 * i << endl;
    }
 
    return 0;
}


Output:

12 x 1 = 12
12 x 2 = 24
12 x 3 = 36
12 x 4 = 48
12 x 5 = 60
12 x 6 = 72
12 x 7 = 84
12 x 8 = 96
12 x 9 = 108
12 x 10 = 120


Last Updated : 20 Mar, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments