You are here

log function in C

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

Declaration: double log(double);

C program to find logarithm of a number

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

int main()
{
  double n, result;

  printf("Enter a number to calculate its natural logarithm (base = e)\n");
  scanf("%lf", &n);

  result = log(n);

  printf("Natural log of %.2lf = %lf\n", n, result);

  return 0;
}

Output of program:
log math.h C programming