您的位置:首页 > 其它

poj 1517 u Calculate e

2016-03-18 11:15 381 查看
u Calculate e

Time Limit: 1000MSMemory Limit: 10000K
Total Submissions: 19465Accepted: 11362Special 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 1
1 2
2 2.5
3 2.666666667
4 2.708333333
...


#include<stdio.h>
#include<string.h>
#include<cstdio>
#include<string>
#include<math.h>
#include<algorithm>
#define LL long long
#define PI atan(1.0)*4
#define DD double
#define MAX 2002000
#define mod 100
#define dian 1.000000011
#define INF 0x3f3f3f
using namespace std;
int main()
{
LL n,m,j,i,t,k;
printf("n e\n");
printf("- -----------\n");
DD sum=0;
printf("0 1\n");
for(i=1;i<=9;i++)
{
printf("%d ",i);
DD ans=1;
for(j=1;j<=i;j++)
ans*=j;
sum+=1/ans;
printf("%.10g\n",sum+1);
}
return 0;
}


  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: