C++ double 数据类型取模

来源:百度知道 编辑:UC知道 时间:2024/06/19 01:55:28

原型函数
double fmod ( double numerator, double denominator );

例如:
#include <stdio.h>
#include <math.h>
int main ()
{
printf ("fmod of 5.3 / 2 is %lf\n", fmod (5.3,2) );
printf ("fmod of 18.5 / 4.2 is %lf\n", fmod (18.5,4.2) );
return 0;
}

fmod of 5.3 / 2 is 1.300000
fmod of 18.5 / 4.2 is 1.700000

除法取余。

这还需要取模吗?
#include <iostream>
using namespace std;
int main(){
double k;
double j;//被除数与除数
cin>>k>>j;
int temp=k/j;//强制转换为int求得其商
temp=temp*j;
int k=k-temp;//求得余数
cout<<k;
cin.get();
cin.get();
}