#include <stdio.h>
#include <math.h>
#define PI 3.1415926
int main()
{
float sum = 0, term = 1, h;
int n = 1, t = 1,x;
int T;
scanf("%d", &T);
while (T--) {
scanf("%d", &x);
if (x <= 0 || x >= 180) continue;
h = x * PI / 180.0;
sum = h; term = h; t = -1; n = 1;
while (fabs(term) >= 0.000001) {
term *= h * h /((2 * n + 1) * 2 * n);
sum += t * term;
t = -t;
n++;
}
printf("%.6f", sum);
if (T) printf("\n");
}
return 0;
}
你的结果没问题啊,仅仅是输入次序跟题目有点出入,你的结果是这样的。
把程序改成
就跟题目一致了