[HDU] [2011] Polynomial Summation

Problem Description

Loading...

Problem Analysis

So it turns out I can keep submitting after all…
Did I miscount the number of attempts…
The main difficulty here is using the double type

cpp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
#include<stdio.h>
#include<math.h>
int main() {
	int j,k,x;
	int n[1000];
	double sum,i;
	scanf("%d",&k);
	for(j=0; j<k; j++) {
		scanf("%d",&n[j]);
	}
	for(x=0; x<k; x++) {
		sum=0;
		for(i=0; i<n[x]; i++) {
			sum=sum+pow(-1,i)/(i+1);
		}
		printf("%.2lf\n",sum);
	}
	return 0;
}

Loading...