C Standard Library

C <math.h> - log() Function



The C <math.h> log() function returns the natural logarithm of a given number.

Syntax

double log (double x);
float logf (float x);
long double logl (long 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 example below, 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

5