C log 函数

C log 函数是用于计算给定数字以 E 为底的对数值的数学函数之一。log 函数的语法是:

double log(double number);

log 函数示例

math 函数允许您找到以 E 为底的对数值。此程序将查找不同数字的对数值并显示输出。

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

int main()
{
    printf("\n The Logarithmic Value of 0       = %.4f ", log(0));
    printf("\n The Logarithmic Value of 1       = %.4f ", log(1));
    
    printf("\n The Logarithmic Value of 5       = %.4f ", log(5));
    printf("\n The Logarithmic Value of 16.4    = %.4f ", log(16.4));
    
    printf("\n The Logarithmic Value of -9.32   = %.4f ", log(-9.32));  
    printf("\n The Logarithmic Value of -15.34  = %.4f ", log(-15.34));
  
    return 0;
}
C log Function to find the Natural Logarithmic Value Example

math log 示例 2

在此 C 编程 示例中,我们允许用户输入自己的数字。接下来,此 程序 使用 math log 函数查找用户给定的数字以 E 为底的对数值。

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

int main()
{
    float num, logValue;

    printf(" Please Enter any Numeric :  ");
    scanf("%f", &num);
  
    logValue = log(num);
  
    printf("\n Logarithmic of %.2f = %.4f ", num, logValue);
  
    return 0;
}
 Please Enter any Numeric :  25.765

 Logarithmic of 25.76 = 3.2490