D大叫我要勤更新,好吧,再贴一个HDU的ACM题,这道很简单,相当简单,小牛以上的都请路过

原题:http://acm.hdu.edu.cn/showproblem.php?pid=1012

其实就是用它给出的一个公式计算e的近似值,好了,贴代码,顺便透露一下,下一篇日志,我将写一下上次热烈讨论的HDU 1042 ,尽请期待~

01 /* *******************
02 *Author: Wang Runzhen 
03 *Date:   2010.2.9
04 ******************** */
05 #include<stdio.h>
06 int main(void)
07 {
08     int i,j,k=1;
09     double e=0.0;
10     printf(“n e\n– ———–\n);
11 
12     for(i=0;i<10;i++){
13         for(j=1;j<=i;j++)
14         {
15             k*=j;
16         }
17         e+=(double)1/k;
18         if(i<=1)
19             printf(“%d %.0f\n,i,e);
20         else if(i==2)
21             printf(“%d %.1f\n,i,e);
22         else
23             printf(“%d %.9f\n,i,e);
24         k=1;
25     }
26     return 0;
27 }
Tags: . 5,044 views
Home

5 Comments so far

Trackbacks/Pingbacks

Leave a comment

Name(required)
Mail (required),(will not be published)
Website(recommended)

Fields in bold are required. Email addresses are never published or distributed.

Some HTML code is allowed:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>
URLs must be fully qualified (eg: http://blog.nlogn.cn),and all tags must be properly closed.

Line breaks and paragraphs are automatically converted.

Please keep comments relevant. Off-topic, offensive or inappropriate comments may be edited or removed.