1012 u Calculate e

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 1

1 2

2 2.5

3 2.666666667

4 2.708333333

5 2.716666667

6 2.718055556
7 2.718253968
8 2.718278770
9 2.718281526

 1 #include<stdio.h>
 2 int jc(int n)
 3 {
 4     int i=1,s=1;
 5     if(n==1||n==0)
 6     return 1;
 7     while(i<=n)
 8     {
 9         s*=i;
10         i++;
11     }
12     return s;
13 }
14 int main()
15 {
16     double a[10];
17     a[0]=1;
18     for(int i=1;i<=9;i++)
19     {
20         a[i]=1.0/jc(i)+a[i-1];
21     }
22     printf("n e\n");
23     printf("- -----------\n");
24     for(int i=0;i<=9;i++)
25     {
26         if(i!=8)
27         printf("%d %.10g\n",i,a[i]);
28         else
29         printf("%d %.9f\n",i,a[i]);
30     }
31     return 0;
32 }
时间: 2024-11-25 11:32:05

1012 u Calculate e的相关文章

hdu 1012:u Calculate e(数学题,水题)

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 28686    Accepted Submission(s): 12762 Problem Description A simple mathematical formula for e iswhere n is allowed to go to infinit

poj 1517 &amp; hdu 1012 u Calculate e(简单阶乘)

POJ链接 :http://poj.org/problem?id=1517 HDU链接:http://acm.hdu.edu.cn/showproblem.php?pid=1012 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 o

HDU 1012 u Calculate e(简单阶乘计算)

传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1012 u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 52607    Accepted Submission(s): 24106 Problem Description A simple mathematical

HDU 1012 u Calculate e【暴力打表,水】

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 46844    Accepted Submission(s): 21489 Problem Description A simple mathematical formula for e is where n is allowed to go to infini

水题/hdu 1012 u Calculate e

题意 求n=0~9时的sigma(1/n!) 分析 因为刚学c++ 所以对浮点操作还是很不熟练,正好来了这么一道题 Accepted Code 1 /* 2 PROBLEM:hdu 1012 3 AUTHER:Nicole Lam 4 MEMO:水题 5 */ 6 #include<iostream> 7 #include<iomanip> 8 using namespace std; 9 double a[10]; 10 int main() 11 { 12 cout<&l

Hdu 1012 u Calculate e

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 46276    Accepted Submission(s): 21237 Problem Description A simple mathematical formula for e is where n is allowed to go to infini

杭电 1012 u Calculate e【算阶乘】

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1012 解题思路:对阶乘递归求和 反思:前面3个的输出格式需要注意,可以自己单独打印出来,也可以在for循环里面更改输出小数的位数,另外读题还是要仔细,输出的有9位小数. #include<stdio.h> double sum(int n) { int i; double x=1,s=0; if(n==0) return 1; else { s=1; for(i=1;i<=n;i++) {

HDU 1012.u Calculate e【水】【8月16】

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 generat

hdoj 1012 u Calculate e

u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 37350    Accepted Submission(s): 16905 Problem Description A simple mathematical formula for e is where n is allowed to go to infini

(HDU)1012 --u Calculate e(计算e)

问题描述e的一个简单的数学公式 其中n允许取无穷大, 这实际上可以使用相对小的n值产生非常准确的e近似值. 输出输出由上述公式生成的e的近似值,n的值从0到9.输出的开头应该类似于下面显示的. 示例输出n e- -----------0 11 22 2.53 2.6666666674 2.708333333 1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 6 double fac(int x)