C++次方函數(shù)支持浮點(diǎn)數(shù)嗎

c++
小樊
94
2024-07-25 16:22:10

是的,C++的冪函數(shù)(pow)支持浮點(diǎn)數(shù)作為參數(shù)。例如,可以通過調(diào)用pow函數(shù)來(lái)計(jì)算一個(gè)浮點(diǎn)數(shù)的指數(shù)值,如下所示:

#include <iostream>
#include <cmath>

int main() {
    double base = 2.5;
    double exponent = 3.0;
    double result = std::pow(base, exponent);
    std::cout << base << " raised to the power of " << exponent << " is " << result << std::endl;
    
    return 0;
}

這段代碼將輸出:2.5 raised to the power of 3 is 15.625。因此,C++的pow函數(shù)可以用于計(jì)算任意浮點(diǎn)數(shù)的冪運(yùn)算。

0