C++ Math remainder()函数
函数找到分子/分母的浮点余数(四舍五入到最近的整数值)。
公式如下
Remainder = numerator - (r*denominator)
其中,r = 分子/分母,四舍五入为最接近的整数值。
语法
假设分子为’n’,分母为’d’。语法如下:
return_type remainder(data_type n,data_type d);
注意:返回值类型可以是float、double或long double。
参数
n :分子的值。
d :分母的值。
返回值
它返回n除以d的浮点数余数。
示例1
让我们看一个简单的示例。
#include
#include
#include
using namespace std;
int main()
{
float n=5.7;
float d=8.9;
std::cout << "Values of numerator and denominator are :" <
输出:
Values of numerator and denominator are :5.7 , 8.9
Remainder is :-3.2