You are here

log function

log function returns natural logarithm (base is e) of a number, where e is the exponential number.

Declaration: double log(double);

C programming code for log

  1. #include <stdio.h>
  2. #include <math.h>
  3.  
  4. int main()
  5. {
  6.   double n, result;
  7.  
  8.   printf("Enter a number to calculate it's natural log (base is e)\n");
  9.   scanf("%lf", &n);
  10.  
  11.   result = log(n);
  12.  
  13.   printf("Natural log of %.2lf = %lf\n", n, result);
  14.  
  15.   return 0;
  16. }

Output of program:
log math.h c programming