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 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
 
按照上边的公式 从0求到9 输出即可                注:小技巧(我看到的想记录下来,与本题无关)printf输出的时候printf("%.5g",n);可以将小数点后边的没用的0去掉如 9.231000可输出9.231
 
#include<stdio.h>
#include<string.h>
double b[20];
double fun(int x)
{
int i;
double sum=1.0,a=1.0;
for(i=1;i<=x;i++)
{
sum=a*sum;
a=a+1;
}
sum=1/sum;
return sum;
}
int main()
{
int n,m,j,i;
double sum=0;
b[0]=1;b[1]=1;
for(i=2;i<=9;i++)
b[i]=fun(i);
printf("n e\n");
printf("- -----------\n");
for(i=0;i<=9;i++)
{
printf("%d ",i);
sum+=b[i];
if(i==2)
{
printf("2.5\n");
continue;
}
if(sum==(int)(sum))
printf("%d\n",(int)(sum));
else
printf("%.9lf\n",sum);
}
return 0;
}

  

hdoj 1012 u Calculate e的更多相关文章

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

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

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

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

  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. ACM YTU 1012 u Calculate e

    u Calculate e Problem Description A simple mathematical formula for e is where n is allowed to go to ...

  5. HDOJ(HDU) 2139 Calculate the formula(水题,又一个用JavaAC不了的题目)

    Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) 看到这个时间,我懵逼了... 果然,J ...

  6. 杭电 1012 u Calculate e【算阶乘】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1012 解题思路:对阶乘递归求和 反思:前面3个的输出格式需要注意,可以自己单独打印出来,也可以在for ...

  7. HDU 1012 u Calculate e

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

  8. 1012 u Calculate e

    A simple mathematical formula for e iswhere n is allowed to go to infinity. This can actually yield ...

  9. Problem : 1012 ( u Calculate e )

    /*tips:本题只有输入,没有输出,在线测试只检测结果,所以将前面几个结果罗列出来就OK了.为了格式输出问题纠结了半天,最后答案竟然还是错的....所以啊,做题还是得灵活变通.*/ #include ...

随机推荐

  1. UILabel 属性祥记

    创建label UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 40, 280, 80)]; 设置背景色 label1. ...

  2. 【win8技巧】应用商店里面如何搜索应用app

    win8应用商店搜索app软件的技巧 1.组合键 WIN+C 打开屏幕最右边磁条 2.点击搜索,输入你想搜的软件名称,里面会列出你已经安装的app或者你点击下面的应用商店选项,就可以搜索互联网上应用商 ...

  3. Fiddler对安卓应用手机抓包图文教程

    http://www.cr173.com/html/37625_1.html 做开发需要抓取手机app的http/https的数据包,想看APP发出的http请求和响应是什么,这就需要抓包了,这可以得 ...

  4. Hansight

    http://www.hansight.com/scenarios.html#account

  5. 【NOIP 2014 DAY1 T3】飞扬的小鸟(DP)

    题目描述 Flappy Bird 是一款风靡一时的休闲手机游戏.玩家需要不断控制点击手机屏幕的频率来调节小鸟的飞行高度,让小鸟顺利通过画面右方的管道缝隙.如果小鸟一不小心撞到了水管或者掉在地上的话,便 ...

  6. MongoDB实战指南(一):大数据与云计算

    1.1 什么大数据 具体来说,大数据技术涉及到数据的创造,存储,获取和分析,大数据的主要特点有下面几个: 数据量大.一个典型的PC机载2000年前后其存储空间可能有10GB,今天facebook一天增 ...

  7. 开发完整的Web项目必备

    开发工具 数据库系统 DB2数据库 Oracle数据库 SQL Server数据库 MySQL数据库 Access数据库 Web服务器 IIS BEA WebLogic Server Apache T ...

  8. 转:理解 Linux 的硬链接与软链接

    Linux 的文件与目录 现代操作系统为解决信息能独立于进程之外被长期存储引入了文件,文件作为进程 创建信息的逻辑单元可被多个进程并发使用.在 UNIX 系统中,操作系统为磁盘上的文本与图像.鼠标与键 ...

  9. Caused by: java.lang.ClassNotFoundException: javax.persistence.EntityListeners

    Answer: This seems to be caused by Hibernate 3.6. It is now dependent on JPA, so it must have a JPA ...

  10. 结构体dict_index_t;

    /** InnoDB B-tree index */ typedef struct dict_index_struct dict_index_t; /** Data structure for an ...