n从0取到9,一个for循环,n++,n=0,n<=9

n=4,求1/4!+1/3!+1/2!+1/1!+1/0!

需要一个for循环,i=n,i>=0,i--

sum+=factorial(i)

即是第一个for循环定下一个n,第二个for循环用这个值递减到0

WA几次:

技巧:%g可以用来省略多余的0,如1.000000,我定义了浮点,可我就%g下,输出1

发现:1.%.10g小数点后只有9位,有的第九位是0,小数点后就只有8位

   2.发现c语言的特性:对的1:

int main()
{
double a;
int temp=9;
a=1.0/temp;
printf("%lf",a);
}

  对的2:

int main()
{
double a;
int temp=9;
a=(double)1/temp;
printf("%lf",a);
}

  错的:

int main()
{
double a;
int temp=9;
a=(double)(1/temp);
printf("%lf",a);
}

  代码如下:改天看大数阶乘

#include <stdio.h>
#include <stdlib.h>
int factorial(int index)
{
int i,temp=1;
if(index==0)
return 1;
else{
for(i=index;i>0;i--)
{
temp=temp*i;
}
return temp;
}
} int main()
{
int n,i;
printf("n e\n");
printf("- -----------\n");
for(n=0;n<10;n++)
{
double sum=0;
for(i=n;i>=0;i--)
{
sum+=(double)1/factorial(i);
}
printf("%d %.10g\n",n,sum);
}
return 0;
}

  

poj--1517的更多相关文章

  1. OpenJudge/Poj 1517 u Calculate e

    1.链接地址: http://bailian.openjudge.cn/practice/1517 http://poj.org/problem?id=1517 2.题目: 总时间限制: 1000ms ...

  2. poj 1517 u Calculate e

    u Calculate e Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 19465   Accepted: 11362   ...

  3. poj 1517 u Calculate e(精度控制+水题)

    一.Description A simple mathematical formula for e is e=Σ0<=i<=n1/i! where n is allowed to go t ...

  4. poj 题目分类(1)

    poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...

  5. POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)

    本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...

  6. poj 1338 Ugly Numbers(丑数模拟)

    转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=1338&q ...

  7. POJ题目细究

    acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP:  1011   NTA                 简单题  1013   Great Equipment     简单题  102 ...

  8. 【转】POJ百道水题列表

    以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...

  9. 转载:poj题目分类(侵删)

    转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码)  ...

  10. POJ——T3417 Network

    http://poj.org/problem?id=3417 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5294   A ...

随机推荐

  1. USB device & USB controller & USB passthrough

    目录 USB device USB controller Linux 相关命令 Python 相关库 Libvirt USB passthrough 参考资料 近期往 openstack 里倒腾 US ...

  2. MEMS陀螺仪—MEMS产品中的杀手

    MEMS陀螺仪(gyroscope)将成为MEMS产品的杀手.它已经被大量地应用在消费和汽车产品上.它的性能每两年提高十倍,它的成本却由于集成度和需求量的提高而不断下降.一旦MEMS陀螺仪的价格下降到 ...

  3. 一篇memcache基础教程

    Memcache是什么Memcache是danga.com的一个项目,最早是为 LiveJournal 服务的,目前全世界不少人使用这个缓存项目来构建自己大负载的网站,来分担数据库的压力.它可以应对任 ...

  4. linux之SQL语句简明教程---表格连接

    现在我们介绍连接 (Join) 的概念.要了解连接,我们需要用到许多我们之前已介绍过的指令.我们先假设我们有以下的两个表格, Store_Information 表格 Store_Name Sales ...

  5. 关于mwArray和一般数组的区别

    可以用下面的代码详细理解mwArray和一般数组之间的区别 mwArray a(, , mxDOUBLE_CLASS); double *aData; aData = ]; int iii; ; ii ...

  6. 借贷宝推广得现金是真的_注册就送人民币20元_邀请码CRJYQTK

    动动手指,20元立即到手.即优步uber打车和滴滴专车豪投数亿元争夺专车市场之后,一款名为借贷宝的APP推广在网上流传开来,目前主要看重的就是它的推广力度,豪投20亿让大众来推广.简单流程:下载借贷宝 ...

  7. 写一个将当前页面 URL 中的 get 参数解析成一个对象的方法。

    function getQuery () { var args = {}; var query = window.location.search.substring(1); var pairs = q ...

  8. 后缀数组da3模板

    在做poj2406的时候...按论文给的rmq模板会超内存...然后网上找了http://blog.csdn.net/libin56842/article/details/46310425这位大爷的d ...

  9. hdu 4521 线段树改点求点的应用

    小明系列问题——小明序列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Tot ...

  10. leetcode_question_102 Binary Tree Level Order Traversal

    Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, ...