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() 函數的用法。

#include <stdio.h>
#include <math.h>

int main ()
{
   float a, b;
   int c;
   a = 9.2;
   b = 3.7;
   c = 2;
   printf("%f / %d 的餘數是 %lf\n", a, c, fmod(a,c));
   printf("%f / %f 的餘數是 %lf\n", a, b, fmod(a,b));

   return(0);
}

讓我們編譯並運行上面的程式,這將產生以下結果:

9.200000 / 2 的餘數是 1.200000
9.200000 / 3.700000 的餘數是 1.800000

C 標準庫 - <math.h> C 標準庫 - <math.h>