这个 比率_减去_等于() 是C++中的一个内置函数,它检查比率R1是否小于或等于R2。如果比率小于或等于比率2,则返回True,否则返回false。 语法:
null
template < class ratio1_name, class ratio2_name > ratio_less_equal
模板参数 该函数接受两个模板参数 比率1 和 比率2 这些都是可以比较的。 返回值: 如果ratio1小于或等于ratio2,则函数返回布尔值,否则返回false。 以下程序说明了上述功能: 项目1:
CPP
// C++ program to illustrate the // ratio_less_equal function // when both the ratios are equal #include <iostream> #include <ratio> using namespace std; int main() { typedef ratio<3, 9> ratio1; typedef ratio<1, 3> ratio2; // check if R1<=R2 if (ratio_less_equal<ratio1, ratio2>::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:
CPP
// C++ program to illustrate the // ratio_less_equal function // to show less than #include <iostream> #include <ratio> using namespace std; int main() { typedef ratio<1, 3> ratio1; typedef ratio<1, 2> ratio2; // check if R1<=R2 if (ratio_less_equal<ratio1, ratio2>::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:
CPP
// C++ program to illustrate the // ratio_less_equal function // to show when greater than #include <iostream> #include <ratio> using namespace std; int main() { typedef ratio<1, 8> ratio1; typedef ratio<1, 10> ratio2; // check if R1<=R2 if (ratio_less_equal<ratio1, ratio2>::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
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END