ACM YTU 1012 u Calculate e
u Calculate e
where n is allowed to go to infinity. This can actually yield very accurate approximations of e using relatively small values of n.
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的更多相关文章
- HDU 1012 u Calculate e(简单阶乘计算)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1012 u Calculate e Time Limit: 2000/1000 MS (Java/Oth ...
- HDU 1012 u Calculate e【暴力打表,水】
u Calculate e Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- 杭电 1012 u Calculate e【算阶乘】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1012 解题思路:对阶乘递归求和 反思:前面3个的输出格式需要注意,可以自己单独打印出来,也可以在for ...
- hdu 1012:u Calculate e(数学题,水题)
u Calculate e Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- hdoj 1012 u Calculate e
u Calculate e Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- YTU 1012: A MST Problem
1012: A MST Problem 时间限制: 1 Sec 内存限制: 32 MB 提交: 7 解决: 4 题目描述 It is just a mining spanning tree ( 最 ...
- ACM YTU 2018 母牛的故事
母牛的故事 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- ACM YTU 十进制与八进制的转换 (栈和队列) STL栈调用
十进制与八进制的转换(栈和队列) Description 对于输入的任意一个非负十进制整数,利用栈打印输出与其等值的八进制数. Input 111 Output 157 Sample Input 14 ...
- ACM YTU 挑战编程 字符串 Problem A: WERTYU
Problem A: WERTYU Description A common typing error is to place yourhands on the keyboard one row to ...
随机推荐
- jQuery 参考手册 - 效果
(speed可选:规定动画的速度.默认是 "normal",可能的值:毫秒(比如 1500)"slow""normal""fast ...
- Response.Write,Page.RegisterClientScriptBlock和Page.RegisterStartupScript的区别
Response.Write("<script>");输出在文件头部,一打开就执行. RegisterClientScriptBlock一般返回的是客户端函数的包装, ...
- Android 快捷方式
1. 需要权限: <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT&quo ...
- git diff old mode 100755 new mode 100644
755 vs 644 在linux下载了Qt的软件仓库,拷贝了一份到windows下.在 msysgit 下,发现所有的文件都被修改了. 用 git diff 查看,发现是: $ git diff u ...
- [转]在MacOS和iOS系统中使用OpenCV
OpenCV 是一个开源的跨平台计算机视觉库,实现了图像处理和计算机视觉方面的很多通用算法. 最近试着在MacOS和iOS上使用OpenCV,发现网上关于在MacOS和iOS上搭建OpenCV的资料很 ...
- Shell if else语句
if 语句通过关系运算符判断表达式的真假来决定执行哪个分支.Shell 有三种 if ... else 语句: if ... fi 语句: if ... else ... fi 语句: if ... ...
- 腾讯sdk配置
android-mirror.bugly.qq.com
- Maven使用第三方jar文件的两种方法 转
在Maven中,使用第三方库一般是通过pom.xml文件中定义的dependency从远程repository中下载该库.但是如果库文件是公司内部的库,或者在本地而不能通过远程repository下载 ...
- Javascript substr方法在某些浏览器下行为出现BUG的补丁代码
主要思路是使用兼容性和稳定性都保持一致的substring方法重写/覆盖substr /** * String.substr() bug fix * @param start * @param len ...
- Razor 语法快速参考
Razor 语法快速参考 本文引自:http://haacked.com/archive/2011/01/06/razor-syntax-quick-reference.aspx 语法名称 Raz ...