该函数找到分子/分母的浮点余数并四舍五入为零。
fmod= numerator - t*denominator
其中" t"是分子/分母的截断值。
考虑一个分子“ n”和分母“ d”。语法为:
double fmod(double n,double d);
n :分子的值。
d :分母的值
它返回n/d的浮点余数。
让我们看一个具有相同类型参数的简单示例。
#include <iostream> #include<math.h> using namespace std; int main() { double n=4.2; double d=7.8; std::cout << "The values of numerator and denominator are :" <<n<<" , "<< d<< std::endl; std::cout << "fmod of these values is :"<<fmod(n,d) <<std::endl; return 0; }
输出:
The values of numerator and denominator are :4.2 , 7.8 fmod of these values is :4.2
让我们看一下具有不同类型参数的简单示例。
#include <iostream> #include<math.h> using namespace std; int main() { float n=7.8; int d=9; std::cout << "The values of numerator and denominator are :" <<n<<" , "<< d<< std::endl; std::cout << "fmod of these values is :"<<fmod(n,d) <<std::endl; return 0; }
输出:
The values of numerator and denominator are :7.8 , 9 fmod of these values is :7.8
让我们看一个简单的例子,当分母的值为零时。
#include <iostream> #include<math.h> using namespace std; int main() { float n=16.7; int d=0; std::cout << "The values of numerator and denominator are :" <<n<<" , "<< d<< std::endl; std::cout << "fmod of these values is :"<<fmod(n,d) <<std::endl; return 0; }
输出:
The values of numerator and denominator are :16.7 , 0 fmod of these values is :-nan
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)