The C log function is one of the math functions useful to calculate the logarithmic value of the given number with base E. The syntax of the log function is
double log(double number);
log Function Example
The math Function allows you to find the logarithmic value of base E. This program will find the logarithmic value of different numbers and display the output.
#include <stdio.h> #include <math.h> int main() { printf("\n The Logarithmic Value of 0 = %.4f ", log(0)); printf("\n The Logarithmic Value of 1 = %.4f ", log(1)); printf("\n The Logarithmic Value of 5 = %.4f ", log(5)); printf("\n The Logarithmic Value of 16.4 = %.4f ", log(16.4)); printf("\n The Logarithmic Value of -9.32 = %.4f ", log(-9.32)); printf("\n The Logarithmic Value of -15.34 = %.4f ", log(-15.34)); return 0; }
math log Example 2
In this C Programming example, we allow users to enter their own numbers. Next, this program uses the math log function to find the logarithmic value of the user-given number with base E.
#include <stdio.h> #include <math.h> int main() { float num, logValue; printf(" Please Enter any Numeric : "); scanf("%f", &num); logValue = log(num); printf("\n Logarithmic of %.2f = %.4f ", num, logValue); return 0; }
Please Enter any Numeric : 25.765
Logarithmic of 25.76 = 3.2490