码迷,mamicode.com
首页 > 其他好文 > 详细

1012 u Calculate e

时间:2017-05-07 14:53:47      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:log   ==   this   form   val   value   actual   put   div   

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

标签:log   ==   this   form   val   value   actual   put   div   

原文地址:http://www.cnblogs.com/97-ly/p/6820660.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!