u Calculate e - 1517

来源:互联网 发布:浏览器ip代理软件 编辑:程序博客网 时间:2024/06/08 10:23
u Calculate e
Time Limit: 1000MS
Memory Limit: 10000KTotal Submissions: 19242
Accepted: 11267
Special Judge

Description

A simple mathematical formula for e is 
e=Σ0<=i<=n1/i!

where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n.

Input

No input

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 Input

no input

Sample Output

n e- -----------0 11 22 2.53 2.6666666674 2.708333333...

Source

法1:由于题中就让输出10以内的n,采用递归比较简单:

法2:采用递推也可以,如果n比较大的情况下,采用递推可以节省时间:


0 0
原创粉丝点击