C++ Math Remainder()
C++ Math Remainder()
该函数查找分子/分母的浮点余数(四舍五入为最接近的整数值)。
余数公式:
Remainder = numerator-(r*denominator)
其中,r =分子/分母,并四舍五入为最接近的整数值。
语法
考虑分子" n"和分母" d"。语法为:
return_type remainder(data_type n,data_type d);
注意: return_type可以是float,double或long double。
参数
n : 分子的值。
d : 分母的值。
返回值
它返回n/d的浮点余数。
示例1
让我们看一个简单的示例。
#include <iostream>
#include<math.h>
#include <cfenv>
using namespace std;
int main()
{
float n=5.7;
float d=8.9;
std::cout << "Values of numerator and denominator are :" <<n <<" , "<<d<<std::endl;
cout<<"Remainder is :"<<remainder(n,d);
return 0;
}
输出:
Values of numerator and denominator are :5.7 , 8.9
Remainder is :-3.2