u Calculate e

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 35137 Accepted Submission(s): 15824

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,最后决定用printf控制格式

#include <iostream>
#include <iomanip>
#include <cstdio>
using namespace std;
double a;
double sum[10];
int main()
{
a=1;
sum[0]=1;
sum[1]=2;
for(int i=2; i<=9; i++)
{
a=a*(1.0/i);
sum[i]=a+sum[i-1];
}
cout<<"n e"<<endl;
cout<<"- -----------"<<endl;
cout<<"0 1"<<endl;
cout<<"1 2"<<endl;
cout<<"2 2.5"<<endl;
for(int i=3;i<=9;i++)
{
printf("%d %.9f\n",i,sum[i]);
}
return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。

u Calculate e 分类: HDU 2015-06-19 22:18 14人阅读 评论(0) 收藏的更多相关文章

  1. 全方位分析Objcetive-C Runtime 分类: ios技术 2015-03-11 22:29 77人阅读 评论(0) 收藏

    本文详细整理了 Cocoa 的 Runtime 系统的知识,它使得 Objective-C 如虎添翼,具备了灵活的动态特性,使这门古老的语言焕发生机.主要内容如下: 引言 简介 与Runtime交互 ...

  2. C/C++文字常量与常变量的概念与区别 分类: C/C++ 2015-06-10 22:56 111人阅读 评论(0) 收藏

    以下代码使用平台是Windows 64bits+VS2012. 在C/C++编程时,经常遇到以下几个概念:常量.文字常量.符号常量.字面常量.常变量.字符串常量和字符常量,网上博客资料也是千篇千律,不 ...

  3. 百度编辑器UEditor ASP.NET示例Demo 分类: ASP.NET 2015-01-12 11:18 346人阅读 评论(0) 收藏

    在百度编辑器示例代码基础上进行了修改,封装成类库,只需简单配置即可使用. 完整demo下载 版权声明:本文为博主原创文章,未经博主允许不得转载.

  4. Network 分类: POJ 图论 2015-07-27 17:18 17人阅读 评论(0) 收藏

    Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 14721 Accepted: 5777 Special Judg ...

  5. 快速幂取模 分类: ACM TYPE 2014-08-29 22:01 95人阅读 评论(0) 收藏

    #include<stdio.h> #include<stdlib.h> //快速幂算法,数论二分 long long powermod(int a,int b, int c) ...

  6. Poj 1029 分类: Translation Mode 2014-04-04 10:18 112人阅读 评论(0) 收藏

    False coin Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 16418   Accepted: 4583 Descr ...

  7. Hibernate检索方式 分类: SSH框架 2015-07-10 22:10 4人阅读 评论(0) 收藏

    我们在项目应用中对数据进行最多的操作就是查询,数据的查询在所有ORM框架中也占有极其重要的地位.那么,如何利用Hibernate查询数据呢?Hibernate为我们提供了多种数据查询的方式,又称为Hi ...

  8. 指向函数的指针 分类: C/C++ 2015-07-13 11:03 14人阅读 评论(0) 收藏

    原文网址:http://www.cnblogs.com/zxl2431/archive/2011/03/25/1995285.html 讲的很清楚,备份记录. (一) 用函数指针变量调用函数 可以用指 ...

  9. Red and Black(BFS or DFS) 分类: dfs bfs 2015-07-05 22:52 2人阅读 评论(0) 收藏

    Description There is a rectangular room, covered with square tiles. Each tile is colored either red ...

随机推荐

  1. 2.Spring Web MVC的优势

    清晰的角色划分:前端控制器(DispatcherServlet).请求到处理器映射(HandlerMapping).处理器适配器(HandlerAdapter).视图解析器(ViewResolver) ...

  2. ads 错误

    这个问题已经不是第一次碰到了,每次弄周立功的EasyARM2210的时候都会遇见,每次都没有记住.就是要用ADS运行板子配套光盘里面的配套程序的时候会出现: (Fatal)L6002U:Could n ...

  3. Maven教程(转载)

    转载自:http://www.yiibai.com/maven/ Apache Maven是一个软件项目管理和综合工具.基于项目对象模型(POM)的概念,Maven可以从一个中心资料片管理项目构建,报 ...

  4. Eclipse中进行Gradle+Jetty部署的web项目的断点调试

    1.自行配置好build.gradle文件和按照gradle的web项目目录结构规范建立java.resourece和webapp文件夹 可在build.gradle文件中自由设定“http端口” 1 ...

  5. ASP.NET的一般处理程序对图片文件的基本操作

    以一个小项目为例: 验证码: public class VerifyCodeHelper { public VerifyCodeHelper() { this.ran = new Random(); ...

  6. vs2010打包系统必备选择.net framework 3.5sp1编译错误的解决方法

    利用visual studio 2010进行打包程序,默认安装的是Framework 4.0,如果需要将3.5sp1打包到系统中一起安装(选择了"从与我的应用程序相同的位置下载系统必备组件& ...

  7. SPOJ COT3 Combat on a tree(Trie树、线段树的合并)

    题目链接:http://www.spoj.com/problems/COT3/ Alice and Bob are playing a game on a tree of n nodes.Each n ...

  8. Demo12SimpleAdapter

    /Users/alamps/AndroidStudioProjects/Demo12SimpleAdapter/Demo12SimpleAdapter/src/main/res/layout/data ...

  9. demo04calc

    package com.example.demo05simplecalc; import android.os.Bundle; import android.app.Activity; import ...

  10. mysql 线程池 数据库连接池

    当客户端请求的数据量比较大的时候,使用线程池可以节约大量的系统资源,使得更多的CPU时间和内存可以高效地利用起来.而数据库连接池的使用则将大大提高程序运行效率,同时,我们可以通过其自身的管理机制来监视 ...