poj--1517
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的更多相关文章
- OpenJudge/Poj 1517 u Calculate e
1.链接地址: http://bailian.openjudge.cn/practice/1517 http://poj.org/problem?id=1517 2.题目: 总时间限制: 1000ms ...
- poj 1517 u Calculate e
u Calculate e Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 19465 Accepted: 11362 ...
- 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 ...
- poj 题目分类(1)
poj 题目分类 按照ac的代码长度分类(主要参考最短代码和自己写的代码) 短代码:0.01K--0.50K:中短代码:0.51K--1.00K:中等代码量:1.01K--2.00K:长代码:2.01 ...
- POJ题目分类(按初级\中级\高级等分类,有助于大家根据个人情况学习)
本文来自:http://www.cppblog.com/snowshine09/archive/2011/08/02/152272.spx 多版本的POJ分类 流传最广的一种分类: 初期: 一.基本算 ...
- poj 1338 Ugly Numbers(丑数模拟)
转载请注明出处:viewmode=contents">http://blog.csdn.net/u012860063? viewmode=contents 题目链接:id=1338&q ...
- POJ题目细究
acm之pku题目分类 对ACM有兴趣的同学们可以看看 DP: 1011 NTA 简单题 1013 Great Equipment 简单题 102 ...
- 【转】POJ百道水题列表
以下是poj百道水题,新手可以考虑从这里刷起 搜索1002 Fire Net1004 Anagrams by Stack1005 Jugs1008 Gnome Tetravex1091 Knight ...
- 转载:poj题目分类(侵删)
转载:from: POJ:http://blog.csdn.net/qq_28236309/article/details/47818407 按照ac的代码长度分类(主要参考最短代码和自己写的代码) ...
- POJ——T3417 Network
http://poj.org/problem?id=3417 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5294 A ...
随机推荐
- createDocumentFragment
http://www.cnblogs.com/myjavascript/p/3708920.html 对于循环批量操作页面的DOM有很大帮助!利用文档碎片处理,然后一次性append,并且使用原生的j ...
- Unix/Linux环境C编程入门教程(27) 内存那些事儿
calloc() free() getpagesize() malloc() mmap() munmap()函数介绍 calloc(配置内存空间) 相关函数 malloc,free,realloc,b ...
- Nutch环境搭建
1. 环境准备 HOST:Ubuntu12.04LTS JDK: jdk-7u45-linux-i586.rpm Nutch:apache-nutch-1.7-bin.tar.gz Solr:solr ...
- linux之普通用户与root用户之间切换
- redhat 安装virtualbox
1.在官网下载virtual for linux 包,链接地址:https://www.virtualbox.org/wiki/Linux_Downloads.根据需要下载对应镜像. 2.由于下载的包 ...
- sharepoint 2010 使用自定义列表模版创建列表(1)
我们在使用sharepoint的过程中,发现一个比较好用的功能,就是“将此列表另存为模版”(save list as template),这个功能的作用是,创建一个和当前列表或者文档库一模一样的配置, ...
- 基于Andoird 4.2.2的同步框架源代码学习——同步提供端
Android同步框架 同步(synchronization)允许用户将远程数据下载到新的设备上,同时将设备上的帐户数据上传到远端.同步还保证用户能够看到最新的数据. 开发者自然可以通过自己的方式来设 ...
- how to translate the text of push button
Background:In a project, the need to translate the buttons on the screen, as shown below,the followi ...
- multiset集合容器的集合运算:并、交、差
set和multiset的内部通常是采用平衡二叉树来实现.当放入元素时,会按照一定的排序方法自动排序,默认是按照less<>排序规则来排序.这种自动排序的特性加速了元素查找的过程,但问题是 ...
- 好用的DNS服务器推荐
DNS在平时上网中扮演重要角色,如果不注意DNS的话,可能会导致网速慢.弹窗广告.网址打不开.打开不是自己想要的网站.淘宝客劫持等一系列问题.针对DNS的问题,网络上也有各种DNS平台供用户选择.这里 ...