c语言remainder函数,C++ remainder() 函数使用方法及示例

C++ remainder() 函数使用方法及示例

C ++中的restder()函数计算分子/分母的浮点余数(四舍五入到最接近的值)。remainder (x, y) = x - rquote * y

其中,rquote是x/y的结果,四舍五入到最接近的整数值(一半情况下四舍五入到偶数)。

restder()原型[从C ++ 11标准开始]double remainder(double x, double y);

float remainder(float x, float y);

long double remainder(long double x, long double y);

double remainder(Type1 x, Type2 y); // Additional overloads for other combinations of arithmetic types

restder()函数接受两个参数,并返回double,float或long double类型的值。

此函数在头文件中定义。

restder()参数x -分子的值。

y -分母的值。

restder()返回值

restder()函数返回x/y的浮点余数(四舍五入到最接近的值)。

如果分母y为零,则remainder()返回NaN(不是数字)。

示例1:remainder()如何在C ++中工作?

示例#include 

#include 

using namespace std;

int main()

{

double x = 7.5, y = 2.1;

double result = remainder(x, y);

cout <

x = -17.50, y=2.0;

result = remainder(x, y);

cout <

y=0;

result = remainder(x, y);

cout <

return 0;

}

运行该程序时,输出为:余数 7.5/2.1 = -0.9

余数 -17.5/2 = 0.5

余数 -17.5/0 = -nan

示例2:用于不同类型参数的remainder()函数

示例#include 

#include 

using namespace std;

int main()

{

int x = 5;

double y = 2.13, result;

result = remainder(x, y);

cout <

return 0;

}

运行该程序时,输出为:余数  5/2.13 = 0.74

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值