Hdu ::u Calculate e

来源:互联网 发布:sql*plus不能启动 编辑:程序博客网 时间:2024/06/06 20:41

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.
 

Sample Output
n e- -----------0 11 22 2.53 2.6666666674 2.708333333

注意格式就行:

#include <stdio.h>   int main(){  double e=2.5;int n=3; double fact=2;   printf("n e\n- -----------\n"); printf("0 1\n");   printf("1 2\n");   printf("2 2.5\n");    while (n<10) { fact*=n; e+=1.0/fact; printf("%d %.9lf\n",n,e);n++; }return 0; } 


0 0
原创粉丝点击