C++ 中的 Ratio_less_equal 函数


给定的任务是展示在 c++ 中 ratio_less_equal () 函数的工作原理。

给定的函数 Ratio_less_equal 检查 ratio1 的值是否小于或等于 ratio2。它返回布尔常量“值”,如果 ratio1 小于或等于 ratio2 则返回真,否则返回假。

语法

template ratio_less_equal

参数

此函数接受两个模板参数,一个是 ratio1,另一个是 ratio2,它们将被比较。

此函数的说明

在此函数中,如果 ratio1 的值小于或等于 ratio2 的值,则此函数将返回布尔值,即 true,即整数位 1,否则将返回 false,即整数位 0。

例如

Input: 1/3 and 3/9
Output: 1/3 is less than or equal to 3/9.
Input: 1/4 and 1/4
Output: 1/4 is equal to 1/4.

我们在以下程序中使用的方法

  • 首先我们声明两个比率。

  • 然后分配两个比率的值。

  • 然后我们检查 ratio1 的值是否小于或等于 ratio2 的值。

  • 使用 ratio_less_equal 我们可以检查

范例

// C++ code demonstrate the working of ratio_less_equal
#include<iostream.h>
#include<ratio.h>
Using namespace std;
Int main( ){
   typedef ratio<1, 3> ratio1;
   typedef ratio<3, 9> ratio2;
   if(ratio_less_equal<ratio1, ratio2>: : value)
      cout<< “ ratio1 is less than or equal to ratio2”;
   else
      cout<< “ ratio1 is not less than or equal to ratio2”;
   return 0;
}

输出

如果我们运行上述代码,它会生成以下输出。

1/3 is less than or equal to 3/9.
4/16 is not less than or equal to 1/4.

更新于: 02-3-2020

48 次浏览

开启您的 职业生涯

通过完成本课程获得认证

开始学习
广告
© . All rights reserved.