-3
那麼,我在網上尋找一個代碼來計算e(e^x)的功率,並找到了一些很好的代碼。然後我找到下面的代碼,只是想知道n = 999部分和< = 100部分應該做什麼?我的意思是,爲什麼n < = 100?爲什麼n = 999?計算e(e^x)的功效,爲什麼n = 999?
#include<stdio.h>
#define ACCURACY 0.0001
int main() {
int n, count;
float x, term, sum;
printf("\nEnter value of x :");
scanf("%f", &x);
n = term = sum = count = 1;
while (n <= 100) {
term = term * x/n;
sum = sum + term;
count = count + 1;
if (term < ACCURACY)
n = 999;
else
n = n + 1;
}
printf("\nTerms = %d Sum = %f", count, sum);
return 0;
}
它意味着無限。 – leppie
n = 999旨在打破循環。 –
它作爲while循環終止邏輯工作,n = 101也是如此 – Pooya