u Calculate e
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 19296 Accepted Submission(s): 8425
Problem Description
A simple mathematical formula for e is where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n.
Output
Output the approximations of e generated by the above formula for the values of n from 0 to 9. The beginning of your output should appear similar to that shown below.
Sample Output
n e
- -----------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333
Source
Recommend
JGShining
#include#include double run(int n){ if(n == 0 || n == 1) return 1; else return run(n-1)*n;}int main(){ int n, i, j; double sum[11]; memset(sum, 0, sizeof(sum)); printf("n e\n- -----------\n0 1\n1 2\n2 2.5\n"); sum[2] = 2.5; for(i=3; i<=9; i++) { sum[i] = sum[i-1] + 1.0/run(i); printf("%d %.9lf\n", i, sum[i]); }}
WA的情况并没有那么唯一的,捉襟见肘的感觉很难见到AC的那一刻,做题需要严谨和耐心,WA多次没问题,挣扎成长只是暂时
如果没有这个提示,我想我会再禁锢一段时间
n e
- -----------0 11 22 2.53 2.6666666674 2.7083333335 2.7166666676 2.7180555567 2.7182539688 2.7182787709 2.718281526这是AC的数据,注意n=8的情况,最后面无意义的0还是要保留。所以n=0、1、2作为特殊值输出,剩下的用%.9lf即可,%.10lg就要WA了。