#region //9、用一元人民币兑换成1分、2分和5分硬币,编程,输出所有不同的兑换方法及兑换方法个数。
            //9、用一元人民币兑换成1分、2分和5分硬币,编程,输出所有不同的兑换方法及兑换方法个数。

            //1.全部1分、2分、5分 3种       1分、2分           1分、5分        2分、5分      

            //假如是1元   1分最多100个  2分最多50个  5分最多20个   
            Console.WriteLine("请输入要兑换的金额(单位:元):");
            int result = int.Parse(Console.ReadLine()) * 100;

            //方法个数
            int count = 0;
            for (int x = 0; x <= result; x++)
            {
                for (int y = 0; y <= result / 2; y++)
                {
                    for (int z = 0; z <= result / 5; z++)
                    {
                        if (result == x * 1 + y * 2 + z * 5)
                        {
                            Console.WriteLine("1分:{0}个;2分:{1}个;5分:{2}个。", x, y, z);
                            count++;
                        }

                    }
                }

            }
            Console.WriteLine("共计{0}种", count);
            Console.ReadLine();
            #endregion

 

相关文章:

  • 2021-11-01
  • 2022-01-10
  • 2022-12-23
  • 2021-08-18
  • 2022-12-23
  • 2021-12-14
  • 2021-12-02
猜你喜欢
  • 2021-10-22
  • 2021-05-17
  • 2021-05-25
  • 2021-07-29
  • 2022-01-04
相关资源
相似解决方案