C言語におけるexp関数の使い方は何ですか?
C言語では、exp関数は、自然対数の底eをべき乗するために使用されます。その宣言は以下の通りです:
double exp(double x);
xは特定の冪を表す。exp関数はeのx乗の値を返す。
以下は、exp関数を使用する方法を示したサンプルコードです。
#include <stdio.h>
#include <math.h>
int main() {
double x = 2.0;
double result = exp(x);
printf("e raised to the power of %f is %f\n", x, result);
return 0;
}
上記の例では、math.hヘッダーファイルを含めて、exp関数を使用してeの2乗を計算し、結果を出力します。プログラムを実行すると次のようになります:
e raised to the power of 2.000000 is 7.389056