杭电1012-u Calculate e

心已赠人 2022-08-08 14:53 110阅读 0赞

u Calculate e

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 36343 Accepted Submission(s): 16422

Problem Description

A simple mathematical formula for e is

1012-1.gif

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

  1. n e
  2. - -----------
  3. 0 1
  4. 1 2
  5. 2 2.5
  6. 3 2.666666667
  7. 4 2.708333333

这个题主要是找到前后规律,然后打表即可!

AC代码:

  1. #include<cstdio>
  2. int jc(int x)
  3. {
  4. int sum=1;
  5. for(int i=x;i>=1;i--)
  6. {
  7. sum*=i;
  8. }
  9. return sum;
  10. }
  11. int main()
  12. {
  13. double a[11];
  14. int i;
  15. a[0]=1;
  16. for(i=1;i<=9;i++)
  17. a[i]=a[i-1]+1.0/jc(i);
  18. printf("n e\n- -----------\n");
  19. printf("0 1\n1 2\n2 2.5\n");
  20. for(i=3;i<=9;i++)
  21. printf("%d %.9lf\n",i,a[i]);
  22. }

发表评论

表情:
评论列表 (有 0 条评论,110人围观)

还没有评论,来说两句吧...

相关阅读

    相关 2078

    说实话,此题是一道有严重bug的问题,对于xhd没晚能复习的科目数m根本就没用上!!!哎不管那么些了,反正ac了!呵呵!此题这样想xhd得复习效率是前一课程和后一课程复习效率差

    相关 2090

    此题就是一道令人无法琢磨的题!哎!!我简直就无语了!!呵呵!竟然能出这题。。。。 废话少说,直接ac!!! \\\ 此题要想输出结果,还需要注意一下! 在linux