1. 程式人生 > >百錢買百雞問題程序

百錢買百雞問題程序

() namespace str 兩個 spa style font sin clu

 雄雞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

 

百錢買百雞問題程序