C log()

The log() function computes the natural logarithm of an argument.

C log() Prototype

double log( double arg );

The log() function takes a single argument and returns a value of type float.

[Mathematics] logex = log(x) [In C programming]

It is defined in <math.h> header file.

In order to find the log() of long double or float numbers, you can use the following prototype.

long double logl( long double arg);
float logf(float arg);

C log() Arguments

Argument remarks
arg > 0 (Greater than zero)

Finds the log of the argument

arg < 0 (Less thn zero) Shows run-time error

Example: C log() function

#include <stdio.h>
#include <math.h>
int main()
{
    double num = 5.6, result;

    result = log(num);
    printf("log(%.1f) = %.2f", num, result);

    return 0;
}
log(5.6) = 1.72