我也刚学C
练习一下
#include"stdio.h"
double polynomial(int n)
{
double result=0,sign=1;
for (int i =1;i<=n;i++)
{
result+=sign*(1.0/i);
sign*=-1;
}
return result;
}
void main()
{
int num;
int namount;
scanf("%d",&namount);
while(namount>0)
{
scanf("%d",&num);
printf("%lf \n",polynomial(num) );
namount--;
}
}
练习一下
#include"stdio.h"
double polynomial(int n)
{
double result=0,sign=1;
for (int i =1;i<=n;i++)
{
result+=sign*(1.0/i);
sign*=-1;
}
return result;
}
void main()
{
int num;
int namount;
scanf("%d",&namount);
while(namount>0)
{
scanf("%d",&num);
printf("%lf \n",polynomial(num) );
namount--;
}
}