杭电1012--u Calculate e

u Calculate e

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 35178    Accepted Submission(s):
15843

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 1
1 2
2 2.5
3 2.666666667
4 2.708333333

Source

Greater
New York 2000

//水题,格式;

 1 #include<stdio.h>
 2 double sieve[100];
 3 int main()
 4 {
 5     int i, total=1; sieve[0]=1;
 6     for(i=1;i<10;i++)
 7     {
 8         total*=i;
 9         sieve[i]=sieve[i-1]+1.0/total;
10     }
11     printf("n e\n");
12     printf("- -----------\n");
13     int n;
14     for(i=0;i<10;i++)
15     {
16         printf("%d ",i);
17         if(i<=1)
18         printf("%d\n",(int)sieve[i]);
19         else if(i==2)
20         printf("%.1lf\n",sieve[i]);
21         else
22         printf("%.9lf\n",sieve[i]);
23     }
24     return 0;
25 }
时间: 2024-10-12 04:29:11

杭电1012--u Calculate e的相关文章

杭电 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++) {

杭电ACM分类

杭电ACM分类: 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDIATE DECODABILITY

【转】对于杭电OJ题目的分类

[好像博客园不能直接转载,所以我复制过来了..] 1001 整数求和 水题1002 C语言实验题——两个数比较 水题1003 1.2.3.4.5... 简单题1004 渊子赛马 排序+贪心的方法归并1005 Hero In Maze 广度搜索1006 Redraiment猜想 数论:容斥定理1007 童年生活二三事 递推题1008 University 简单hash1009 目标柏林 简单模拟题1010 Rails 模拟题(堆栈)1011 Box of Bricks 简单题1012 IMMEDI

杭电 1003 Max Sum

http://acm.hdu.edu.cn/showproblem.php?pid=1003 Max Sum Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 142781    Accepted Submission(s): 33242 Problem Description Given a sequence a[1],a[2],a[3

杭电 1242 Rescue(广搜)

http://acm.hdu.edu.cn/showproblem.php?pid=1242 Rescue Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15597    Accepted Submission(s): 5663 Problem Description Angel was caught by the MOLIGPY!

杭电 2602 Bone Collector

Bone Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 27413    Accepted Submission(s): 11154 Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bo

杭电1212--Big Number

Big Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 5961    Accepted Submission(s): 4167 Problem Description As we know, Big Number is always troublesome. But it's really important in our

杭电ACM题目分类

杭电ACM题目分类 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028. 1029.1032.1037.1040.1048.1056.1058.1061.1070.1076.1089.1090.1091.1092. 1093.1094.1095.1096.1097.1098.1106.1108.1157.1163.1164.1170.1194.1196. 1197.1201.1202.1205.1219.1234.123

Number Sequence(杭电1005)

/*Number Sequence Problem Description A number sequence is defined as follows: f(1) = 1, f(2) = 1, f(n) = (A * f(n - 1) + B * f(n - 2)) mod 7. Given A, B, and n, you are to calculate the value of f(n). Input The input consists of multiple test cases.

Bone Collector------HDOJ杭电2602(纯01背包问题!!!!!!详解!)

Problem Description Many years ago , in Teddy's hometown there was a man who was called "Bone Collector". This man like to collect varies of bones , such as dog's , cow's , also he went to the grave - The bone collector had a big bag with a volu