C log() function
C log() function - Calculate natural logarithm
Syntax:
double log(double x)
The log() function is used to calculate the natural logarithm (base e) of x.
Parameters:
Name | Description | Required /Optional |
---|---|---|
x | Value whose logarithm is to be found. | Required |
Return value from log()
- Upon successful completion, the function returns the natural logarithm of x.
Example: log() function
The following example shows the usage of log() function.
#include <math.h>
#include <stdio.h>
int main(void)
{
double x = 1.0, y;
y = log(x);
printf("The natural logarithm of %lf is %lf\n", x, y);
x = 10.0;
y = log(x);
printf("The natural logarithm of %lf is %lf\n", x, y);
x = 1000.0;
y = log(x);
printf("The natural logarithm of %lf is %lf\n", x, y);
}
Output:
The natural logarithm of 1.000000 is 0.000000 The natural logarithm of 10.000000 is 2.302585 The natural logarithm of 1000.000000 is 6.907755
C Programming Code Editor:
Previous C Programming: C ldexp()
Next C Programming: C log10()
It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.
https://www.w3resource.com/c-programming/math/c-log.php
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics