Se sabe que hay varios pollos y conejos, con 98 cabezas y 386 pies. Trate de encontrar el número de pollos y conejos por método exhaustivo.

#include<stdio.h>
int main()
{
    //已知有鸡兔若干只, 共有98个头, 386只脚, 试用穷举法求出鸡兔的数量
    short chicken=0;//chicken记录鸡的数量
    printf("chicken   rabbit\n");
    while(chicken<=98)
    {
        if(chicken*2+(98-chicken)*4==386)
        {
            printf("%6hd%6hd\n", chicken, 98-chicken);
        }
        chicken++;
    }
    //
    return 0;
}

Supongo que te gusta

Origin blog.csdn.net/weixin_42048463/article/details/115253977
Recomendado
Clasificación