Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> C++

ฟังก์ชัน exp() ใน C++

ฟังก์ชันไลบรารี C/C++ double exp(double x) คืนค่าของ e ยกกำลัง x ดังนี้คือการประกาศฟังก์ชัน exp()

double exp(double x)

พารามิเตอร์คือค่าจุดทศนิยม ฟังก์ชันนี้คืนค่า exponential value ของ x

ตัวอย่างโค้ด

#include <iostream>
#include <cmath>
using namespace std;

int main() {
    double x = 0;
    cout << "The exponential value of " << x << " is " << exp(x) << endl;
    cout << "The exponential value of " << x+1 << " is " << exp(x+1) << endl;
    cout << "The exponential value of " << x+2 << " is " << exp(x+2) << endl;
    return 0;
}

ผลลัพธ์

The exponential value of 0 is 1
The exponential value of 1 is 2.71828
The exponential value of 2 is 7.38906