📜  C / C++中的isgreaterequal()

📅  最后修改于: 2021-05-30 01:52:13             🧑  作者: Mango

在C++中,isgreaterequal()是用于数学计算的预定义函数。 math.h是各种数学功能所需的头文件。

isgreaterequal()函数,用于检查赋予该函数的第一个参数是否大于或等于赋予该函数的第二个参数。表示如果a是第一个参数, b是第二个参数,那么它将检查a> = b是否。

句法:

bool isgreaterequal(a, b)

    与该函数相关的异常

  • 如果ab或两者均为NaN,则该函数引发异常并返回false(0)。
    // CPP code to illustrate
    // the exception of function
    #include 
    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;
    }
    

    输出:

    5.5 isgreaterequal nan: 0
    

    例子:

  • 程序1:

    // CPP code to illustrate
    // the use of isgreaterequal function
    #include 
    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;
    }
    

    输出:

    5 isgreaterequal to 8: 0
    8 isgreaterequal to 5: 1
    

    注意:使用此函数,您还可以将任何数据类型与任何其他数据类型进行比较。

  • 程式2:
    // CPP code to illustrate
    // the use of isgreaterequal function
    #include 
    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;
    }
    

    输出:

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

应用

在各种应用程序中,我们可以使用isgreaterequal()函数比较两个值,例如在for循环中使用以打印任何数字(例如12)的表。

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

输出:

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
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”