Polynomial summation
Time limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 50228 Accepted Submission (s): 29277
Problem Description
The 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.
Input
The 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.
Output
For 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
2
1 2
Sample Output
1.00
0.50
Author
Lcy
Source
C Language Programming exercises (II.)
#include <stdio.h>
#include <math.h>
int main ()
{
int m,j,i,n;
float sum;
scanf ("%d", &n);
while (n--)
{
scanf ("%d", &m);
for (i=1,sum=0;i<=m;i++)
{
J=pow ( -1, (i+1));
sum+=j* (1.0/i);
}
printf ("%.2\n", sum);
}
}
Polynomial summation AC-Hangzhou Electric