Polynomial summation AC-Hangzhou Electric

Source: Internet
Author: User

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

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.