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 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的阶乘,递归计算一下就行
// 输出的时候要注意保留9位小数,0也保留 #include <iostream>
#include<stdio.h>
using namespace std;
int fun[10];
double a[1000] = {0.0};
int g(int x)//递归求0--9的阶乘
{
int z;
if(x <= 1 )
z = 1;
else
z = g(x-1)*x;
return z;
}
void f()
{
a[0] = 1;
a[1] = 2;
for(int i = 2;i<10;i++)
{
a[i] = a[i-1]+(1/(double)g(i));
}
} int main()
{
f();
cout<<"n e"<<endl;
cout<<"- -----------"<<endl;
cout<<0<<" "<<a[0]<<endl;
cout<<1<<" "<<a[1]<<endl;
cout<<2<<" "<<a[2]<<endl;
for(int i = 3;i<10;i++)
{
printf("%d %11.9f\n",i,a[i]);
//cout.precision(10);
//cout<<i<<" "<<a[i]<<endl;
// C++的cout.precision(x);不保留0,要注意
} //cout<<f(n)<<endl; return 0;
}


ACM YTU 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. 杭电 1012 u Calculate e【算阶乘】

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

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

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

  5. hdoj 1012 u Calculate e

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

  6. YTU 1012: A MST Problem

    1012: A MST Problem 时间限制: 1 Sec  内存限制: 32 MB 提交: 7  解决: 4 题目描述 It is just a mining spanning tree ( 最 ...

  7. ACM YTU 2018 母牛的故事

    母牛的故事 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Subm ...

  8. ACM YTU 十进制与八进制的转换 (栈和队列) STL栈调用

    十进制与八进制的转换(栈和队列) Description 对于输入的任意一个非负十进制整数,利用栈打印输出与其等值的八进制数. Input 111 Output 157 Sample Input 14 ...

  9. ACM YTU 挑战编程 字符串 Problem A: WERTYU

    Problem A: WERTYU Description A common typing error is to place yourhands on the keyboard one row to ...

随机推荐

  1. Web---HTTP请求、重定向、转发和数据压缩

    HTTP常用的请求方式包括: GET-最为常见,但发送的数据量很小,发送的数据直接包含到url的后面. POST-可以包含大量数据,数据在请求正文中通过表单进行提交. HEAD,PUT,DELETE. ...

  2. C# TypeConverter 数据转换

    提供一种将值的类型转换为其他类型以及访问标准值和子属性的统一方法. 自定义Converter: public class GenericListTypeConverter<T> : Typ ...

  3. mysql数据库引擎问题汇总

    可以使用mysql> show engines;查看mysql支持何种引擎, 其中default表明该引擎为默认引擎. 在windows下面的mysql引擎默认为InnoDB,linux下的为 ...

  4. JavaFX 3D部分介绍(3) Lights

    声明:   本博客文章原创类别的均为个人原创,版权所有.转载请注明出处: http://blog.csdn.net/ml3947,另外本人的个人博客:http://www.wjfxgame.com. ...

  5. Sublime_text3怎么运行php代码

    开发神奇sublime写代码真的好爽,之前听说是神器,但是没去用,觉得用eclipse写php代码,用dw写html够用了,用了一下sublime,哈哈,爽爆了. 除了写前端代码外,还需要写php代码 ...

  6. 加速数组操作(Array)

    Measure-Command { $ar = @() for ($x=0; $x -lt 10000; $x++) { $ar += $x } }执行结果:3.301s Measure-Comman ...

  7. javascript split() 正则表达式

    路由匹配 http.createServer(function(req, res) { var items = req.url.split('/'); if (items.length < 3 ...

  8. JVM体系结构

    为了防止无良网站的爬虫抓取文章,特此标识,转载请注明文章出处.LaplaceDemon/SJQ. http://www.cnblogs.com/shijiaqi1066/p/5187049.html ...

  9. struts2 自定义拦截,防止非法操作

    <package name="defaults" extends="struts-default"> <interceptors> &l ...

  10. http://bbs.phpcms.cn/thread-266337-1-1.html

    http://bbs.phpcms.cn/thread-266337-1-1.html utf8  改成 ANSI”