杭电 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++)
    {
        x*=1.0/i;
        s+=x;
    }
    return s;
    }
}
int main()
{
    int i;
    double ss=0;
    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++)
    {
        ss=sum(i);

        printf("%d %.9lf\n",i,ss);
    }

}

  

时间: 2024-11-10 06:22:16

杭电 1012 u Calculate e【算阶乘】的相关文章

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

杭电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

杭电 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!

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

杭电ACM2092--整数解

杭电ACM2092--整数解    分析 http://acm.hdu.edu.cn/showproblem.php?pid=2092 一个YES,一个Yes.试了10几次..我也是无语了..哪里都不错的.... 很简单,用2次求根公式求出其中一个的值,然后判断是否为整数    if (x == int(x) ). 或者  用最直接的方法,从-m到m挨个算.有意结果时停止. 源码: #include <stdio.h> #include <math.h> int main() {

杭电 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

杭电 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