English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

C Language Basic Tutorial

C Language Flow Control

C Language Functions

C Language Arrays

C Language Pointers

C Language Strings

C Language Structure

C Language File

C Others

C Language Reference Manual

C library function log() usage and example

C Standard Library <math.h>

double log(double x) returns the natural logarithm of x (base e logarithm).

C log() function prototype

double log(double arg);

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

It is in<math.h>Defined in the header file.

To find the natural logarithm of long double or float, the following prototype can be used.

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

C log() parameter

ParameterDescription
arg > 0 (greater than zero)Calculate the logarithm of a natural number
arg < 0 (less than zero)Display runtime errors

Example: Usage of 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;
}

Output Result

log(5.6) = 1.72

C Standard Library <math.h>