📜  C++中的ratio_less_equal()函数

📅  最后修改于: 2021-05-30 19:05:07             🧑  作者: Mango

ratio_less_equal()是C++中的内置函数,用于检查比率R1是否小于或等于比率R2。如果比率小于或等于比率2,则返回True;否则返回false。

句法:

template < class ratio1_name, class ratio2_name > ratio_less_equal

模板参数的函数接受两个模板参数比1比*这些都是进行比较。

返回值:如果ratio1小于或等于ratio2,则该函数返回一个布尔值,该值为true,否则返回false。

下面的程序说明了上述函数:

程序1:

// C++ program to illustrate the
// ratio_less_equal function
// when both the ratios are equal
#include 
#include 
using namespace std;
int main()
{
    typedef ratio<3, 9> ratio1;
    typedef ratio<1, 3> ratio2;
  
    // check if R1<=R2
    if (ratio_less_equal::value)
        cout << "3/9 is less than or equal to 1/3";
    else
        cout << "3/9 is greater than 1/3";
  
    return 0;
}
输出:
3/9 is less than or equal to 1/3

程式2:

// C++ program to illustrate the
// ratio_less_equal function
// to show less than
#include 
#include 
using namespace std;
int main()
{
    typedef ratio<1, 3> ratio1;
    typedef ratio<1, 2> ratio2;
  
    // check if R1<=R2
    if (ratio_less_equal::value)
        cout << "1/3 is less than or equal to 1/2";
    else
        cout << "1/3 is greater than 1/2";
  
    return 0;
}
输出:
1/3 is less than or equal to 1/2

程序3:

// C++ program to illustrate the
// ratio_less_equal function
// to show when greater than
#include 
#include 
using namespace std;
int main()
{
    typedef ratio<1, 8> ratio1;
    typedef ratio<1, 10> ratio2;
  
    // check if R1<=R2
    if (ratio_less_equal::value)
        cout << "1/8 is less than or equal to 1/10";
    else
        cout << "1/8 is greater than 1/10";
  
    return 0;
}
输出:
1/8 is greater than 1/10
要从最佳影片策划和实践问题去学习,检查了C++基础课程为基础,以先进的C++和C++ STL课程基础加上STL。要完成从学习语言到DS Algo等的更多准备工作,请参阅“完整面试准备课程”