What is the exp() function in C++?

Overview

The exp() function in C++ is simply used to return the exponential (e) or the Euler’s number raised to the argument given in the function.

Euler’s number = 2.71828

The fmax() function is defined in the <cmath> header file.

Syntax

result = exp(x)

Parameter value

The exp() function takes any value x (negative, zero or positive) as its parameter value.

Return value

The exp() function returns the exponential value of a given number in int, double, float, or long double between zero and infinity.

#include <bits/stdc++.h>
using namespace std;
// function to explain use of exp() function
double Exponentiation(double x)
{
double result = exp(x);
cout << "exp(x) = " << result << endl;
return result;
}
// driver program
int main()
{
double x = 10;
Exponentiation(x);
return 0;
}

Explanation

  • Line 5: We created a function Exponentiation() and passed x as its parameter value.
  • Line 7: We created a command for the function by assigning the exp() function to the variable result.
  • Line 8: We printed the output of the result variable.
  • Line 9: We returned the result variable.
  • Line 14: We assigned the value 10 to x.
  • Line 15: we called the Exponentiation() function to take the exponential of the value 10 that we assigned to x.

Free Resources