二.设计思路
1.初始化cock,hen,chicken;
2.套入循环
①判断cock是否小于等于0,是则进行下一步,否则结束运算;
②判断hen是否小于等于33,是则进行下一步,否则cock增加;
③判断chicken是否小于等于100,是则进行下一步,否则hen增加;
④代入cock,hen和chicken的值进行运算,如果价格总和等于100,则进行下一步输出结果,不等的话chicken继续增加;
#include<bits/stdc++.h> 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 is" << cock << ", "<< "hen is" << hen <<", "<< "chicken is" << chicken <<endl; } } } } return 0; }
标签:4.17,一步,chicken,等于,打卡,cock,hen From: https://www.cnblogs.com/binglinll/p/17326725.html