Open In App

exp() function C++

The exp() function in C++ returns the exponential (Euler’s number) e (or 2.71828) raised to the given argument.

Syntax for returning exponential e: result=exp()

Parameter: The function can take any value i.e, positive, negative or zero in its parameter and returns result in int, double or float or long double. Return Value: The exp() function returns the value in the range of [0, inf]. 



Error:

Application: Given below is an example of application of exp() function 



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

                    

Output
exp(x) = 22026.5
22026.5

Time Complexity: O(1)
Auxiliary Space: O(1)

Here is the program to demonstrate the error in exp() function.

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

                    

Output
exp(x) = inf
inf

Time Complexity: O(1)
Auxiliary Space: O(1)

Applications of e (mathematical constant):

Source : Wiki


Article Tags :
C++