log10 : <math.h> library function

The function double log10(double x); returns the common logarithm of x. The common logarithm is the base-10 logarithm.

Function prototype of log10

double log10(double x);
  • x : A floating point value whose logarithm to be calculated. It must be positive.

Return value of log10

It returns the common logarithm of x. If x is negative, a domain error occurs.

C program to show the use of log10 function

The following program shows the use of log10 function.

#include <stdio.h>
#include <math.h>

int main ()
{
  double x, result;
  /* Logarithm is only defined for positive numbers */
  printf("Enter a positive number\n");
  scanf("%lf", &x);
  
  result = log10(x);
  printf("Logarithm of %lf with base 10 is : %lf", x, result);
  
  return 0;
}

Program Output
Enter a positive number
123
Logarithm of 123.000000 with base 10 is : 2.089905
Enter a positive number
100
Logarithm of 100.000000 with base 10 is : 2.000000