The C log function is one of the C Math Functions, used to calculate the logarithmic value of the given number with base E. The syntax of the log in C Programming is
double log(double number);
C log Function Example
The C math logarithmic Function allows you to find the logarithmic value of base E.
In this program, We are going to find the logarithmic value of different values, and display the output.
/* LOG in C Programming Example */ #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; }
OUTPUT
C log Example 2
In this C Programming example, we are allowing the user to enter their own value. Next, we used the log function to find the logarithmic value of the user-given number with base E.
/* LOG in C Programming Example */ #include <stdio.h> #include <math.h> int main() { float number, logValue; printf(" Please Enter any Numeric Value : "); scanf("%f", &number); logValue = log(number); printf("\n Logarithmic Value of %.2f = %.4f ", number, logValue); return 0; }
OUTPUT