acm2011

/**

* 多项式求和

* 1 - 1/2 + 1/3 - 1/4 + 1/5 - 1/6 + ...

*/

import java.util.*;

public class acm2011{

public static void main(String[] args) {

Scanner in = new Scanner(System.in);

while(in.hasNextInt()){

int n= in.nextInt();

for(int i = 0 ; i < n ; i++){

int a = in.nextInt();

int b= 1;

double sum = 0;

for(int j=1;j<=a; j++){

sum =sum+ b*(1.0/j);

b=b*(-1);

}

System.out.printf("%.2f",sum);

System.out.println();

}

}

}

}

时间: 2024-11-24 06:57:01

acm2011的相关文章