百钱百鸡

#include <stdio.h>

int main()

{

    int i, j, k;

    for (i = 0; i <= 20; i++) //公鸡

    {

        for (j = 0; j <= 33; j++) //母鸡

        {

             //for (k = 0; k <= 100; k+=3)      //小鸡

             //{

             //  if (k / 3 + j * 3 + i * 5 == 100 && i + j + k == 100)

             //      printf("公鸡:%2d 母鸡:%2d 小鸡:%2d\n", i, j, k);

             //}

             k = 100 - i - j;      //减少循环次数

             if (k % 3 == 0 && k / 3 + j * 3 + i * 5 == 100 && i + j + k == 100)

                 printf("公鸡:%2d 母鸡:%2d 小鸡:%2d\n", i, j, k);

        }

    }

    return 0;

}

posted @ 2023-04-13 11:03  258333  阅读(32)  评论(1编辑  收藏  举报