u Calculate e
Time Limit: 1000MS | Memory Limit: 10000K | |||
Total Submissions: 19465 | Accepted: 11362 | 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.
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 "); printf("- ----------- "); DD sum=0; printf("0 1 "); 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 ",sum+1); } return 0; }