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
 
 
简单题
 #include<stdio.h>
int fact(int n)
{
int res=;
while(n>=)
{
res*=n;
n--;
}
return res;
}
int main()
{
printf("n e\n- -----------\n0 1\n1 2\n2 2.5\n3 2.666666667\n4 2.708333333\n");
int n,i;
double e;
for(n=;n<=;n++)
{
e=0.0;
for(i=;i<=n;i++)
{
e+=1.0/double(fact(i));
}
printf("%d %.9lf\n",n,e);
}
return ;
}

HDU 1008 u Calculate e的更多相关文章

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

    u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

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

    传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1012 u Calculate e Time Limit: 2000/1000 MS (Java/Oth ...

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

    u Calculate e Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Tot ...

  4. HDU 1008 电梯( 水题)

    题意: 电梯当前在0层,每在1层需要停5秒,往上走每层需6秒,往下走每层需要4秒. 思路: 在接收输入的时候直接计算了它,不用再弄一个循环.每计算一个请求就更新当前层,停留5秒的等到输出时再加上5*n ...

  5. hdu 1008 注意同层情况

    #include<iostream> using namespace std; int main() { int n; ]; while(cin>>n) { ,m=; ) br ...

  6. hdu 1008 Elevator

    Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Description The hig ...

  7. hdu 1008

    题目意思是:给你N个数字  每个数字表示多少层楼  现在要你从0层楼开始坐电梯  一次按顺序走过这些楼层 规则是 上楼6秒 ,下楼4秒,每次到达一个楼层停5秒..... 思路:模拟 代码如下:(要注意 ...

  8. ACM hdu 1008 Elavator

    Elevator其实是一道水题,思路也很简单,但不知道怎么也不能AC,后来看了别人的再比较自己的以后找到错误. 在判断奇偶数之后的语句时,我用了if()  else if(),这是不能AC的原因,这种 ...

  9. HDU 1012 u Calculate e

    题解:直接模拟 #include <cstdio> int main(){ puts("n e");puts("- -----------");pu ...

随机推荐

  1. ubuntu 下 编译ffmpeg 3.1.1

    1,下载ggmpeg源码:http://ffmpeg.org/download.html 2.下载ndk ,百度 3.配置环境 3.1 编译FFMPEG时,出现了 ffmpeg yasm not fo ...

  2. sellenium页面元素的定位方法

    1.findElements函数可用于多个元素定位 (1)使用ID定位:driver.findElement(By.id("ID值")); 例:HTML代码: 定位语句代码:Web ...

  3. Linux下gcc,g++,gdb,scon部分用法笔记

    1 Ubuntu下编译安装GCC-4.1.2 拷贝gcc-4.1.2.tar.bz2(我下载的压缩文件)到/usr/local/src 解压 新生成的gcc-4.1.2这个目录被称为源目录,用${sr ...

  4. delphi 输入文件相对路径的更改,更改成用户的

  5. leetcode medium

    419. Battleships in a Board --No iven an 2D board, count how many different battleships are in it. T ...

  6. UGUI和现实世界的比例关系

    之前测试过默认大小的 Cube 在现实中的 比例关系,得出基本单位为 m 的结论,至于 UGUI和现实世界的比例关系 看下图就知道了: Cube Collider 的大小: Button 的大小: 其 ...

  7. Linux连接xshell找不到IP信息

    虚拟机环境下的Linux连接xshell的网络连接找不到eth0(IP)信息的解决方法   1  输入ifconfig,如果有eth0信息,直接填写eth0上面的IP信息   2 输入ifconfig ...

  8. const 那点事儿

    修饰变量时 const char 与 char const 是等价的,例如 const char a = 'a'; char const a = 'a'; 表示变量a不能再被赋予其他值. 到指针时情况 ...

  9. iOS开发系列-九宫格算法-xib

    给大家演示 应用程序下载 小项目,效果图:涉及知识点:懒加载,九宫格算法,字典转模型,自定义UIView ,xib文件的使用 首先把素材拖到Xcode项目中:简单看一下素材文件 此时大家应该首先关注. ...

  10. jsp:useBean的使用

    ->Bean的基本要素: 1.必须要有一个不带参数的构造器,在jsp元素创建Bean时会调用空构造器 2.Bean类应该没有任何公共实例变量,也就是说,不允许直接访问实例变量,通过setter/ ...