题目:
公鸡一只五元,母鸡一只三元,三只小鸡一共一元,一百元买一百只鸡可以各买多少只。
代码:
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
int main(void) {
int g,m,x;
for(g=0;g<=20;g++){
for (m=0;m<=33;m++) {
for(x=3;x<=99;x++){
if(5*g+3*m+(x/3)==100){
if(g+m+x==100){
if(x%3==0) {
printf("公鸡%d只,母鸡%d只,小鸡%d只\n", g, m, x);
}
}
}
}
}
}
return 0;
}
结果: