C math - log() Function
The C math log() function is used to return the natural logarithm of a given number.
Syntax
double log(double x);
Parameters
x |
Specify the number. |
Return Value
Returns the natural logarithm of a given number.
If the x is negative, domain error occurs.
Example:
In the below example, log() function is used to calculate the natural logarithm of a given number.
#include <stdio.h> #include <math.h> int main (){ printf("%lf\n", log(10)); printf("%lf\n", log(50)); printf("%lf\n", log(100)); return 0; }
The output of the above code will be:
2.302585 3.912023 4.605170
❮ C <math.h> Library