1012 u Calculate e
Time Limit: 2000/1000 MS(Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 31123 Accepted Submission(s): 13915
Problem Description
A simple mathematical formula for e is
where n is allowed to go to infinity. This can actually yield very accurateapproximations of e using relatively small values of n.
Output
Output the approximations of e generated bythe above formula for the values of n from 0 to 9. The beginning of your outputshould appear similar to that shown below.
Sample Output
n e
- -----------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333
Source
Recommend
JGShining | Wehave carefully selected several similar problems for you: 1013 1021 1020 1014 1019
#include<stdio.h>
int main()
{
int i;
double e,t,k;
e=2.5;
k=2;
printf("n e\n");
printf("- -----------\n");
printf("0 1\n");
printf("1 2\n");
printf("2 2.5\n");
for(i=3;i<=9;i++)
{
k*=i;
t=1/k;
e+=t;
printf("%d %.9lf\n",i,e);
}
return 0;
}
这个题很容易,做的时候也是格式问题,通过这个题,我觉得做那种有小数的还是用C语言比C++好,因为c++也是这样写却没法通过,总有些数位的错误,还有一些格式上的错误,用C语言的时候就能提交成功,所以感觉做数学题目是适合用C语言,好处理小数些。