1012 u Calculate e

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了1012 u Calculate e相关的知识,希望对你有一定的参考价值。

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
5 2.716666667
6 2.718055556
7 2.718253968
8 2.718278770
9 2.718281526
 
 1 #include<stdio.h> 
 2 int jc(int n)
 3 {
 4     int i=1,s=1;
 5     if(n==1||n==0)
 6     return 1;
 7     while(i<=n)
 8     {
 9         s*=i;
10         i++;
11     }
12     return s;
13 }
14 int main()
15 {
16     double a[10];
17     a[0]=1;
18     for(int i=1;i<=9;i++)
19     {
20         a[i]=1.0/jc(i)+a[i-1];
21     }
22     printf("n e\n");
23     printf("- -----------\n");
24     for(int i=0;i<=9;i++)
25     {
26         if(i!=8)
27         printf("%d %.10g\n",i,a[i]);
28         else
29         printf("%d %.9f\n",i,a[i]);
30     }  
31     return 0;
32 }

 

 








以上是关于1012 u Calculate e的主要内容,如果未能解决你的问题,请参考以下文章

HDU 1012 u Calculate e(简单阶乘计算)

HDU 1012 u Calculate e暴力打表,水

Hdu oj 1012 u Calculate e

I - u Calculate e

HDU 1008 u Calculate e

HDU OJ u Calculate e