问个问题?我这个是不是废了
#include<stdio.h>float _sum(float _count);
float sum(float count);
int main(void)
{
int total,total_num;
float res,_res;
printf("Please enter 2 times:");
while(scanf("%d%d",&total,&total_num)==2)
{
if(total<=0 || total_num<=0)
break;
_res= _sum(total_num);
res=sum(total);
printf("_sum:The sum of %d items is %f.\n",total_num,_res);
printf("sum:The sum of %d items is %f.\n",total,res);
printf("Please enter next 2 times:");
}
printf("Bye!\n");
return 0;
}
float _sum(float _count)
{
float i;
float _num=1.0,t_sum=0;
for(i=2;i<_count;i+=1.0)
{
i=_num/i;
t_sum+=i;
}
return t_sum+1.0;
}
float sum(float count)
{
float j;
float num=1.0,tsum=0;
for(j=2;j<count;j+=1.0)
{
if((int)j%2==0)
j=-(num/j);
else
j=num/j;
tsum+=j;
}
return tsum+1.0;
}
[此贴子已经被作者于2019-1-19 18:32编辑过]