c语言两个双精度浮点数相乘子程序,c语言两个浮点数相加_C语言中两个浮点数或双精度数的模数...

c语言两个浮点数相加

As we know that modules also known as the remainder of the two numbers can be found using the modulus (%) operator which is an arithmetic operator in C/C++. The modules operator works with integer values i.e. modulus operator is used to find the remainder of two integer numbers. If the numbers are float or double the the modulus operators doesn't work.

我们知道,也可以使用模数 ( % )运算符(也就是C / C ++中的算术运算符)找到也称为两个数的余数的模块 。 模块运算符使用整数值,即模数运算符用于查找两个整数的余数。 如果数字为float或double ,则模运算符不起作用。

Consider the below example,

考虑下面的示例,

#include

int main()

{

float x = 10.23f;

float y = 3.1f;

float result = x % y;

printf("result = %f\n", result);

return 0;

}

Output:

输出:

main.c: In function ‘main’:

main.c:8:22: error: invalid operands to binary % (have ‘float’ and ‘float’)

float result = x % y;

^

See the output – it says that invalid operands to modulus operator.

看到输出–它表示模数运算符的无效操作数。

Then, how to find the remainder/modulus of two float or double numbers?

然后, 如何找到两个浮点数或双数的余数/模数?

There is a library function remainder(), declared in math.h. It can be used to find the modules of float, double, and integer (also) numbers.

有一个库函数restder() ,在math.h中声明。 它可用于查找float , double和integer(也)数字的模块。

The remainder() function accepts two parameters and returns the remainder.

restder()函数接受两个参数并返回剩余的值。

Syntax:

句法:

remainder(x, y);

Here, x and y are the floating-point or integral values.

此处, x和y是浮点或整数值。

Example 1:

范例1:

#include

#include

int main()

{

float x = 10.23f;

float y = 3.1f;

float result = remainder(x, y);

printf("result = %f\n", result);

return 0;

}

Output:

输出:

result = 0.930000

Example 2:

范例2:

#include

#include

int main()

{

// integer numbers

int a = 10;

int b = 3;

// float numbers

float m = 10.23f;

float n = 3.1f;

// double numbers

double x = 123456789.10;

double y = 1233.1;

printf("remainder(%d,%d) = %lf\n", a, b, remainder(a, b));

printf("remainder(%f,%f) = %lf\n", m, n, remainder(m, n));

printf("remainder(%lf,%lf) = %lf\n", x, y, remainder(x, y));

return 0;

}

Output:

输出:

remainder(10,3) = 1.000000

remainder(10.230000,3.100000) = 0.930000

remainder(123456789.100000,1233.100000) = 50.200000

翻译自: https://www.includehelp.com/c/modulus-of-two-float-or-double-numbers-in-c-language.aspx

c语言两个浮点数相加

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值