C ++中的restder()
在这里,我们将看到remainder()C++方法的功能。该remainder()函数用于计算分子/分母的浮点余数。
因此,余数(x,y)将如下所示。
remainder(x, y) = x – rquote * y
rquote是x/y的值。这四舍五入为最接近的整数值。此函数接受double,float,longdouble类型的两个参数,并返回相同类型的剩余部分,该部分作为参数给出。第一个参数是分子,第二个参数是分母。
示例
#include <iostream>
#include <cmath>
using namespace std;
main() {
double x = 14.5, y = 4.1;
double res = remainder(x, y);
cout << "Remainder of " << x << "/" << y << " is: " << res << endl;
x = -34.50;
y = 4.0;
res = remainder(x, y);
cout << "Remainder of " << x << "/" << y << " is: " << res << endl;
x = 65.23;
y = 0;
res = remainder(x, y);
cout << "Remainder of " << x << "/" << y << " is: " << res << endl;
}输出结果
Remainder of 14.5/4.1 is: -1.9 Remainder of -34.5/4 is: 1.5 Remainder of 65.23/0 is: nan
热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短