c语言的分数求和问题

这个题不管我把while中的条件换成b<=9还是b<=0,亦或是现在的b<=99,答案都是1.00,但是我的程序也没啥错吧,为啥不管循环怎么变答案都是1呢?是这个程序循环了一遍之后就不再循环了吗?为什么会这样?

img

img

img

把int c改成float c; 类型定义错误

修改如下,供参考:

#include <stdio.h>
#include <math.h>
int main()
{
    int b = 1, c = -1;
    float sum = 0;
    while (b <= 100)
    {
        c = -c;
        //c = (int)pow(-1, b + 1);
        sum = sum + 1.0 * c / b;
        b++;
    }
    printf("%.3f", sum);
    return 0;
}