Latest web development tutorials

C 庫函數– log()

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

描述

C庫函數double log(double x)返回x的自然對數(基數為e的對數)。

聲明

下面是log() 函數的聲明。

double log(double x)

參數

  • x --浮點值。

返回值

該函數返回x 的自然對數。

實例

下面的實例演示了log() 函數的用法。

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

int main ()
{
   double x, ret;
   x = 2.7;

   /* 计算 log(2.7) */
   ret = log(x);
   printf("log(%lf) = %lf", x, ret);
   
   return(0);
}

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

log(2.700000) = 0.993252

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