该函数查找分子/分母的浮点余数(四舍五入到最接近的整数值)。
Remainder = numerator - (r*denominator)
其中,r =分子/分母,并且四舍五入为最接近的整数值。
考虑一个分子“ n”和分母“ d”。语法为:
return_type remainder(data_type n,data_type d);
n :分子的值。
d :分母的值。
它返回浮点余数n/d。
让我们看一个简单的例子。
#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
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)