问题描述:一只公鸡值五钱,一只母鸡值三钱,三只小鸡值一钱,现在要用百钱买百鸡,请问公鸡、母鸡、小鸡各多少只?
流程图:
![](/i/l/?n=23&i=blog/3173603/202304/3173603-20230419202800141-1043923079.jpg)
伪代码:
cock<-0
for cock<-0 To 20
hen=0
for hen<-0 To 33
chicken=0
for chicken<-0 To 100
if cock+hen+chicken=100&&cock*5+hen*3+chicken/3=100
output cock,hen,chicken
代码:
#include <iostream>
using namespace std;
int main()
{
int cock,hen,chicken;
for(cock=0;cock<=20;cock++)
{
for(hen=0;hen<=33;hen++)
{
for(chicken=0;chicken<=100;chicken++)
{
if((cock+hen+chicken==100)&&(cock*5+hen*3+chicken/3.0==100))
cout<<cock<<”,”<<hen<<”,”<<chicken<<endl;
}
}
}
return 0;
}
标签:int,hen,chicken,100,cock,打卡 From: https://www.cnblogs.com/chukjbgg333/p/17334536.html