为什么这个while嵌套循环他只会运行一次,而不能达到嵌套的目的呢

int main()
{
    int a = 0, b = 0, c = 0;
    while (a < 15)
    {
        while (b < 23)
        {
            c = 45 - a - b;
            if (a * 3 + b * 2 + 0.5 * c == 45)
                printf("men=%d,women=%d,child=%d\n", a, b, c);
            b++;
        }
        a++;
    }
        return 0;
        }
int main()
{
    int a = 0, b = 0, c = 0;
    while (a < 15)
    {b=0; //每次循环b都要从头开始
        while (b < 23)
        {
            c = 45 - a - b;
            if (a * 6 + b * 4 + c == 90) //浮点数有误差,扩大两倍,用整数计算
                printf("men=%d,women=%d,child=%d\n", a, b, c);
            b++;
        }
        a++;
    }
        return 0;
        }

问题解决的话,请点下采纳

你的b没清0,所以第二个循环不会再嵌套了

b:1
b:2
b:3
b:4
b:5
b:6
b:7
b:8
b:9
b:10
b:11
b:12
b:13
b:14
b:15
b:16
b:17
b:18
b:19
b:20
b:21
b:22
b:23
a:1
a:2
a:3
a:4
a:5
a:6
a:7
a:8
a:9
a:10
a:11
a:12
a:13
a:14
a:15

这是a和 b的循环情况