溫馨提示×

c語言怎么求次方

小億
754
2024-01-14 03:56:58
欄目: 編程語言

在C語言中,可以使用pow函數(shù)來求一個數(shù)的次方。

函數(shù)原型為:

double pow(double x, double y);

其中,x表示底數(shù),y表示指數(shù)。

示例代碼如下:

#include <stdio.h>
#include <math.h>

int main() {
    double base, exponent, result;

    printf("請輸入底數(shù):");
    scanf("%lf", &base);

    printf("請輸入指數(shù):");
    scanf("%lf", &exponent);

    result = pow(base, exponent);

    printf("%.2lf的%.2lf次方為%.2lf\n", base, exponent, result);

    return 0;
}

運行程序后,輸入底數(shù)和指數(shù),程序會計算并輸出結果。

0