Home >>C Math Functions >C math log() function

C math log() function

C math log() function

C math log() function is used to return the natural logarithm (base-e logarithm) of an argument x. This takes a single argument and returns a value of type float. This function is defined in <math.h> header file.

Syntax:
double log(double x)

Parameter Values

x − It is the floating point value.

Here is an example of log() function:

#include <stdio.h>
#include <math.h>
int main () 
{
double x, ret;
x = 2.7;
ret = log(x);
printf("log(%lf) = %lf", x, ret);
return(0);
}

Output:
log(2.700000) = 0.993252
Example-2

#include <stdio.h>
#include <math.h>
int main () 
{
double x, ret;
x = 10.5;
ret = log(x);
printf("log(%lf) = %lf", x, ret);
return(0);
}

Output:
log(10.500000) = 2.351375