私はこのコードを書きました。大丈夫だと思いますが、実行すると悪い結果になります。このコードはオイラー数を計算するためのものです。私はあなたの答えをいただければ幸いです。
私が期待する結果は約2.718281828459045であり、結果は2.718281745910644です。
- 2.718281828459045(予想)
- 2.718281745910644(実際)
コード:
#include <stdio.h>
main() {
int factor, counter, n = 1;
float total = 0, division;
while ( n <= 20 ) {
counter = 1;
factor = n;
while ( counter < n ) {
factor *= ( n - counter );
counter++;
}
division = 1.0 / factor;
total = total + division;
n++;
}
total = total + 1;
printf( "La constante matematica e vale aproximadamente: %.20f\n", total);
return 0;
} /* Finaliza funcion main */