杭电1012

红太狼 2022-06-05 11:56 227阅读 0赞

u Calculate e

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 18822 Accepted Submission(s): 8211

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
  8. //杭电1012
  9. #include <stdio.h>
  10. int main (int argc, char **argv)
  11. {
  12. printf("n e\n");
  13. printf("- -----------\n");
  14. printf("0 1\n");
  15. printf("1 2\n");
  16. printf("2 2.5\n");
  17. double result = 2.5 ;
  18. double p = 0.5;
  19. for (int i = 3; i <= 9; ++ i )
  20. {
  21. p /= i;
  22. result += p;
  23. printf("%d %.9f\n", i , result);
  24. }
  25. return 0;
  26. }

发表评论

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

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

相关阅读

    相关 2075

    此题真的是简单的再不能简单了!呵呵!我一直纠结,出这样的题是什么意思呢?不懂!哎,不说那些废话了,直接 ac吧!呵呵! \include<iostream> using

    相关 2078

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

    相关 2090

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