log function(Natural Logarithm) in C Language – example and detail

In the C Programming Language, the log feature returns the logarithm of x to the base of e.

Syntax

The syntax for the log characteristic in the C Language is:

double log(double x);

Parameters or Arguments

x A price used in the calculation of the logarithm of x to the base of e. If x is negative, the log function will return a area error. If x is zero, the log characteristic will return a range error.

Returns

The log characteristic returns the logarithm of x to the base of e.

Required Header

In the C Language, the required header for the log feature is:

#include <math.h>

Applies To

In the C Language, the log feature can be used in the following versions:

ANSI/ISO 9899-1990

log Example

/* Example using log by TechOnTheNet.com */

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

int main(int argc, const char * argv[])
{
    /* Define temporary variables */
    double value;
    double result;

    /* Assign the value we will calculate the log of */
    value = 1.5;

    /* Calculate the log of the value */
    result = log(value);

    /* Display the result of the calculation */
    printf("The Natural Logarithm of %f is %f\n", value, result);

    return 0;
}

When compiled and run, this software will output:

The Natural Logarithm of 1.500000 is 0.405465

Similar Functions

Other C features that are similar to the log function:

exp characteristic log10 function pow characteristic