int main() //分数求和 1-100( 带加减)如 1/1-1/2+1/3-1/4......
{
int a = 0;
double sum = 0.0; //int sum = 0; 因为是小数所以要用double
int i = 1;
for (a = 1; a <= 100; a++)
{
sum += i*1.0 / a;
i = -i; //这个作为加减的转换
}
printf("sum = %lf", sum);
return 0;
}
记录每日学习29
最新推荐文章于 2024-08-29 10:03:03 发布