C library - log10() function



The C library log10() function of type double accepts the parameter(x) that returns the common logarithm(base-10 logarithm) of x.

Syntax

Following is the syntax of the C library function log10()

double log10(double x)

Parameters

This function accepts only a single parameter −

  • x − This is the floating point value.

Return Value

This function returns the common logarithm of x in which the value of x greater than zero.

Example 1

Following is the C library program that illustrates the usage of log10() function.

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

int main () {
   double x, ret;
   x = 10000;
  
   /* finding value of log1010000 */
   ret = log10(x);
   printf("log10(%lf) = %lf\n", x, ret);
   
   return(0);
}

Output

On execution of above code, we get the following result −

log10(10000.000000) = 4.000000

Example 2

To calculate the sum of two logarithms(base 10), we can use the following formula −

log10​(a) + log10​(b) = log10​(a.b)

Here, the formula is implemented in C program.

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

int main() {

   // The given positive integers
   double a = 22.0; 
   double b = 56.0; 

   double sum_of_logs = log10(a * b);
   printf("Log10(%lf) + Log10(%lf) = Log10(%.6lf) = %.6lf\n", a, b, a * b, sum_of_logs);
   return 0;
}

Output

After executing the code, we get the following result −

Log10(22.000000) + Log10(56.000000) = Log10(1232.000000) = 3.090611
Advertisements