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() functiondouble Exponentiation(double x){double result = exp(x);cout << "exp(x) = " << result << endl;return result;}// driver programint main(){double x = 10;Exponentiation(x);return 0;}
Explanation
- Line 5: We created a function
Exponentiation()and passedxas its parameter value. - Line 7: We created a command for the function by assigning the
exp()function to the variableresult. - Line 8: We printed the output of the
resultvariable. - Line 9: We returned the
resultvariable. - Line 14: We assigned the value
10tox. - Line 15: we called the
Exponentiation()function to take the exponential of the value10that we assigned tox.