在这里,我们将看到如何在C中获取两个浮点或双精度类型数据的模数。模数基本上是找到余数。为此,我们可以使用C中的remainder()函数。remainder()函数用于计算分子/分母的浮点余数。
因此,remainder(x, y)将如下所示。
remainder(x, y) = x – rquote * y
rquote 是 x/y 的值。这将四舍五入到最接近的整数值。该函数接受两个类型为 double、float、long double 的参数,并返回作为参数给出的相同类型的剩余部分。第一个参数是分子,第二个参数是分母。
#include <stdio.h> #include <math.h> main() { double x = 14.5, y = 4.1; double res = remainder(x, y); printf("Remainder of %lf/%lf is: %lf</p><p>",x,y, res); x = -34.50; y = 4.0; res = remainder(x, y); printf("Remainder of %lf/%lf is: %lf</p><p>",x,y, res); x = 65.23; y = 0; res = remainder(x, y); printf("Remainder of %lf/%lf is: %lf</p><p>",x,y, res); }
Remainder of 14.500000/4.100000 is: -1.900000 Remainder of -34.500000/4.000000 is: 1.500000 Remainder of 65.230000/0.000000 is: -1.#IND00
以上就是使用C语言计算两个浮点数或双精度数的模数的详细内容,更多请关注php中文网其它相关文章!
C语言怎么学习?C语言怎么入门?C语言在哪学?C语言怎么学才快?不用担心,这里为大家提供了C语言速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号