Polynomial summationTime
limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 52871 Accepted Submission (s): 30814
problem Descriptionthe polynomial is described as follows:
1-1/2 + 1/3-1/4 + 1/5-1/6 + ...
Now ask you to find out the first n of the polynomial.
InputThe input data consists of 2 lines, the first is a positive integer m (m<100), the number of test instances, the second row contains m positive integers, and for each integer (may be set to n,n<1000), the first n of the polynomial.
Outputfor each test instance n, the number of the first n items of the output polynomial is required. The output of each test instance is one row, and the result retains 2 decimal places.
Sample Input
21 2
Sample Output
1.000.50
Source
<span style= "FONT-SIZE:18PX;" >//2011 #include <stdio.h> #include <math.h>int n,m;double t;int main () {scanf ("%d", &n), while (n--) { Double sum=0;//note the position of sum assigned to the initial value, which should be scanf in the while loop ("%d", &m); for (double i=1;i<=m;i++) {T=pow ( -1,i+1) *1.00;sum+=1/i *t;} printf ("%.2lf\n", sum);} return 0;} </span>
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
HDU 2011 Polynomial summation