C 库函数

C 库函数 - fmod()

转自:C 标准库 - <math.h> C 标准库 - <math.h> 

描述

C 库函数 double fmod(double x, double y) 返回 x 除以 y 的余数。

声明

下面是 fmod() 函数的声明。

double fmod(double x, double y)

参数

  • x -- 代表分子的浮点值。
  • y -- 代表分母的浮点值。

返回值

该函数返回 x/y 的余数。

实例

下面的实例演示了 fmod() 函数的用法。

 1 #include <stdio.h>
 2 #include <math.h>
 3 
 4 int main ()
 5 {
 6    float a, b;
 7    int c;
 8    a = 9.2;
 9    b = 3.7;
10    c = 2;
11    printf("%f / %d 的余数是 %lf
", a, c, fmod(a,c));
12    printf("%f / %f 的余数是 %lf
", a, b, fmod(a,b));
13    
14    return(0);
15 }

让我们编译并运行上面的程序,这将产生以下结果:

1 9.200000 / 2 的余数是 1.200000
2 9.200000 / 3.700000 的余数是 1.800000

C 标准库 - <math.h> C 标准库 - <math.h>

原文地址:https://www.cnblogs.com/minmin123/p/11942112.html