In C++, the log()
function is used to return the natural logarithm of the argument x
that is passed to it.
Mathematically, the natural logarithm of a number is given by:
Log(x) = Log x
double log (double x);
float log (float x);
long double log (long double x);
The log()
function takes a single parameter value x
, which represents the number whose natural logarithm is to be computed. This parameter value must be between zero (0
) and infinity(∞
).
Any value passed to the function that is less than zero (0
) will return NaN
.
The log()
function returns the natural logarithm of the argument x
that is passed to it.
#include <iostream>#include <cmath>using namespace std;int main (){// creating variablesint x = 100;double result;// implementing the log() functionresult = log (x);cout << "log(100) = " << result << endl;return 0;}
x
and result
.log()
function on the value of the x
variable and assign the output to the result
variable.result
variable.