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. NOI2007 货币兑换

    [问题描述] 小 Y最近在一家金券交易所工作.该金券交易所只发行交易两种金券:A纪念券(以下简称A券)和B纪念券(以下简称B券).每个持有金券的顾客都有一个自己的 帐户.金券的数目可以是一个实数.每天 ...

  2. SQL基础之 时间戳

    本文转载:http://www.cnblogs.com/liuhh/archive/2011/05/14/2046544.html 一直对时间戳这个概念比较模糊,相信有很多朋友也都会误认为:时间戳是一 ...

  3. 基于Shading Model(对光照变化一定不变性)的运动目标检测算法

    光照模型(Shading Model)在很多论文中得到了广泛的应用,如robust and illumination invariant change detection based on linea ...

  4. mysql加入�管理员

    1.首先用超级管理员登录,然后点击权限button 2.点击加入�新用户,填写登录名和password,全局权限不用选,点击新建用户button 3.编辑新加入�的用户(编辑权限) 4.找到" ...

  5. careercup-栈与队列 3.2

    3.2 请设计一个栈,除pop与push方法,还支持min方法,可返回栈元素中的最小值.push.pop和min三个方法的时间复杂度必须为O(1). 我们假设除了用一个栈s1来保存数据,还用另一个栈s ...

  6. LabVIEW的错误簇以及错误处理函数

    我们可以在LabVIEW的Modern>>Array, Matrix & Cluster控件面板找到表示错误簇数据类型的错误输入(Error In)以及错误输出(Error Out ...

  7. Publisher/Subscriber(发布/订阅者)消息模式开发流程

    该模式的作用是发布者和订阅者 可以相互发送消息 发布者和订阅者都充当 生产者和消费者 发布者 package publisher.to.subscriber; import java.awt.font ...

  8. SourceTree - 好用的 Git / Mercurial GUI 管理工具 for Mac OS X

    Git 是免費.開放源碼的分散式版本控制系統,從小專案到非常大的專案,都可以很快速.有效地管理. 對程式設計師來說,一定要熟記 git 指令的用法,在終端機下操作 git 是必備的基本技能.(其他的 ...

  9. mvvm框架下页面与ViewModel的各种参数传递方式

    传单个参数的话在xaml用     Command={Binding ViewModel的事件处理名称}    CommandParameter={Binding 要传递的控件名称} ViewMode ...

  10. hdu2002

    import java.util.*;class Main{public static void main(String args[]){Scanner cin=new Scanner(System. ...