2025-03-06 22:46:33 +08:00

27 lines
757 B
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*-------------------------------------------------------
百钱买百鸡,《算经》一书中记载
“鸡翁一值钱五,鸡母一值钱三,鸡雏三值钱一,百钱买百鸡,问鸡翁、鸡母、鸡雏各几何?”
要求每一种鸡都要有编程输出公鸡gj、母鸡mj、小鸡xj各有多少只。
结果:(注使用for循环
公鸡有4只母鸡有18只小鸡有78只
公鸡有8只母鸡有11只小鸡有81只
公鸡有12只母鸡有4只小鸡有84只
-------------------------------------------------------*/
#include <stdio.h>
void main()
{
int gj,mj,xj;
/**********Program**********/
for(gj=1;gj<20;gj++){
for(mj=1;mj<34;mj++){
for(xj=3;xj<300;xj+=3){
if(gj+mj+xj==100 && gj*5+mj*3+xj/3 == 100)
/********** End **********/
printf("公鸡有%d只母鸡有%d只小鸡有%d只\n",gj,mj,xj);
}
}
}
}