HDU 1012 U calculate E

Source: Internet
Author: User
U calculate E

Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 13241 accepted submission (s): 5725

Problem descriptiona 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.

 

Outputoutput
The approximations of E generated by the above formula for the values
Of N from 0 to 9. The beginning of your output shoshould appear similar
That shown below.

Sample outputn E
------------
0 1
1 2
2 2.5
3 2.666666667
4 2.708333333

Source greater New York 2000
1 // note the output format
2 # include <stdio. h>
3 # include <string. h>
4 # include <stdlib. h>
5
6
7 int DP [100];
8 double sum [100];
9
10
11 void fun (int n)
12 {
13 int I;
14
15 DP [0] = 1;
16
17 For (I = 1; I <= N; I ++)
18 DP [I] = DP [I-1] * I;
19
20}
21
22 int main ()
23 {
24 int I, j, N;
25 memset (DP, 0, sizeof (DP ));
26 memset (sum, 0, sizeof (SUM ));
27 fun (10 );
28 sum [0] = 1;
29 for (I = 1; I <= 9; I ++)
30 sum [I] = sum [I-1] + 1.0/dp [I];
31 printf ("n e \ n------------ \ n ");
32 For (I = 0; I <= 9; I ++ ){
33 If (sum [I] = (INT) sum [I])
34 printf ("% d \ n", I, INT (sum [I]);
35 else if (I = 2)
36 printf ("% d %. 1lf \ n", I, sum [I]);
37 Else
38 printf ("% d %. 9lf \ n", I, sum [I]);
39}
40 return 0;
41}
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.