级数求和问题
Time Limit:1000MS Memory Limit:65536K
Total Submit:1428 Accepted:641
Description
计算x-x/2+x/3-x/4+…+x/99-x/100+…,直到最后一项的绝对值小于0.00001为止。
Input
正整数x(1 =< n <= 100)
Output
一个实数,小数点后保留2位。
Sample Input
3
Sample Output
2.08
Source
#include <stdio.h>
//421
int main()
{
int a,b,temp;
int sum=0;
scanf("%d %d",&a,&b);
if(a>b)
{
temp=a;
a=b;
b=temp;
}
for(;a<=b;a++)
{
sum+=a;
}
printf("%d",sum);
return 0;
}