C Standard Library

C <math.h> - log10() Function



The C <math.h> log10() function returns the base-10 logarithm of a given number.

Syntax

double log10 (double x);
float log10f (float x);
long double log10l (long double x);

Parameters

x Specify the number.

Return Value

Returns the base-10 logarithm of a given number.
If the x is negative, domain error occurs.

Example:

In the example below, log10() function is used to calculate the base-10 logarithm of a given number.

#include <stdio.h>
#include <math.h>
 
int main (){
  printf("%lf\n", log10(10));
  printf("%lf\n", log10(50));
  printf("%lf\n", log10(100));
  return 0;
}

The output of the above code will be:

1.000000
1.698970
2.000000

❮ C <math.h> Library

5