HDU 1012 u Calculate e

来源:互联网 发布:思迅软件合作伙伴社区 编辑:程序博客网 时间:2024/05/22 02:00

u Calculate e

Problem Description
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.


简单数学计算,没什么算法。

依照已给公式,算出0-9。

公式题目已给出,注意输出‘-’的个数,前三个短输出,直接printf输出,可以不用计算,题目测试数据已经给出。后面依照公式就可以。

#include <stdio.h>int main(){int n=10;double e=2.5,i=0,sum=1,j;printf("n e\n- -----------\n");printf("0 1\n1 2\n2 2.5\n");for(i=3;i<n;i++){if(i==0)e=1;else{sum=1;for(j=1;j<=i;j++){sum=sum*j;}e=e+(1/sum);} printf("%0.0lf %.9lf\n",i,e);}return 0;}
1 0
原创粉丝点击