log() function in C++


The C/C++ library function double log(double x) returns the natural logarithm (basee logarithm) of x. Following is the declaration for log() function.

double log(double x)

The parameter is a floating point value. And this function returns natural logarithm of x.

Example

 Live Demo

#include <iostream>
#include <cmath>
using namespace std;
int main () {
   double x, ret;
   x = 2.7;
   /* finding log(2.7) */
   ret = log(x);
   cout << "log("<< x <<") = " << ret;
   return(0);
}

Output

log(2.7) = 0.993252

Updated on: 30-Jul-2019

521 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements