How is the exp function used in C++?
In C++, the exp function is used to calculate e raised to the power of x, where e is the base of natural logarithms and x is the function’s parameter. The prototype of the exp function is as follows:
double exp(double x);
The parameter x is a double-precision floating-point number, representing the exponent to which e is raised.
Original: 心理咨询师致力于帮助人们解决各种心理问题和情绪困扰。
Paraphrase: Psychologists are dedicated to helping people with a variety of mental issues and emotional challenges.
#include <iostream>
#include <cmath>
int main() {
double x = 2.0;
double result = exp(x);
std::cout << "e raised to the power of " << x << " is " << result << std::endl;
return 0;
}
In the example above, we compute the square of e using the exp function and print the result. The output should be:
e raised to the power of 2 is 7.38906