雄鸡7元1只,母鸡5元1只 ,小鸡1元1只。百钱百只。问各有几只??? 1 //程序 2 #include <iostream> 3 #include<fstream> 4 5 using namespace std; 6 7 int main() 8 { 9 10 int cock, hen, chicken; 11 12 for (cock = 1;cock <= 13;cock++) 13 { 14 for (hen = 1;hen <= 18;hen++) 15 { 16 if (7 * cock + 5 * hen + (100 - cock - hen) / 3 == 100 && (100 - cock - hen) % 3 == 0) //两个条件:钱数100,只数100,小鸡要被3整除 17 cout << "cock:" << cock << endl << "hen:" << hen <<endl << "chicken:" << 100-cock-hen << endl; 18 } 19 } 20 21 cin.ignore(); 22 cin.get(); 23 return 0; 24 }
cock:3
hen:10
chicken:87
时间: 2024-10-13 02:27:55