namespace 组6角钱 { class Program { public void qian() { int count = 0; for (int yf = 0; yf <= 60; yf++) { for (int ef = 0; ef <= 30; ef++) { for (int wf = 0; wf <= 12; wf++) { if (yf * 1 + ef * 2 + wf * 5 == 60) { count++; Console.WriteLine("第" + count + "种组合方法:一分" + yf + "个,二分" + ef + "个,五分" + wf + "个!"); } } } } Console.WriteLine("总共" + count + "种组合方法!"); } static void Main(string[] args) { Program hanshu = new Program(); //3、有1分钱,2分钱,5分钱的硬币,要组合出来6角钱,有几种组合方式,分别各多少个 //6角=60分 //int count = 0;//数数,符合题意的组合方法 //int bian = 0;//总循环遍数 //for (int yf = 0; yf <= 60; yf++) //{ // for (int ef = 0; ef <= 30; ef++) // { // for (int wf = 0; wf <= 12; wf++) // { // bian++; // if (yf * 1 + ef * 2 + wf * 5 == 60) // { // count++; // Console.WriteLine("第" + count + "种组合方法:一分" + yf + "个,二分" + ef + "个,五分" + wf + "个!"); // } // } // } //} //Console.WriteLine("总共"+count+"种组合方法!"); //Console.WriteLine("总共循环" + bian + "遍!"); hanshu.qian(); Console.ReadLine(); } } }
时间: 2024-09-29 22:07:48