![The C Standard Library Reference](/c_standard_library/images/c-mini-logo.jpg)
- The C Standard Library
- C Library - Home
- C Library - <assert.h>
- C Library - <complex.h>
- C Library - <ctype.h>
- C Library - <errno.h>
- C Library - <fenv.h>
- C Library - <float.h>
- C Library - <inttypes.h>
- C Library - <iso646.h>
- C Library - <limits.h>
- C Library - <locale.h>
- C Library - <math.h>
- C Library - <setjmp.h>
- C Library - <signal.h>
- C Library - <stdalign.h>
- C Library - <stdarg.h>
- C Library - <stdbool.h>
- C Library - <stddef.h>
- C Library - <stdio.h>
- C Library - <stdlib.h>
- C Library - <string.h>
- C Library - <tgmath.h>
- C Library - <time.h>
- C Library - <wctype.h>
- C Standard Library Resources
- C Library - Quick Guide
- C Library - Useful Resources
- C Library - Discussion
- C Programming Resources
- C Programming - Tutorial
- C - Useful Resources
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