题目描述
输入
输出
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
struct node
{
double data;
struct node*next;
};
int main()
{
double t,i,sum;
long long int n;
int x;
struct node *head,*tail,*p;
scanf("%lf",&t);
while(t--)
{ sum=0;
scanf("%lld",&n);
x=n;
head=(struct node*)malloc(sizeof(struct node));
head->next=NULL;
tail=head;
for(i=1;i<=1000;i++)
{
p=(struct node*)malloc(sizeof(struct node));
p->data=pow(-1,i-1)*(double)(1/i);
p->next=NULL;
tail->next=p;
tail=p;
}
p=head->next;
if(x>1000)
{
for(i=1;i<=1000;i++)
{
sum=sum+p->data;
p=p->next;
}
}
else for(i=1;i<=x;i++)
{
sum=sum+p->data;
p=p->next;
}
printf("%.2lf\n",sum);
}
return 0;
}
//该题大于1000之后的数的倒数近乎0可以忽略所以只求前1000