在C#中开发一种算法,以给出购买的确切变化(金额)? [英] Develop an algorithm in C# to give exact change(money) for a Purchase ?
本文介绍了在C#中开发一种算法,以给出购买的确切变化(金额)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,
在C#中开发一种算法,以给出购买的确切变化(金额).
印度卢比.
输入是卢比的变化.
输出是硬币和纸币的数量.
假设硬币是Re.1,Rs.2.
这些纸币是5,10,20,50,100,500,1000.这是我们的印度卢比纸币.
请帮助解决此问题
在此先感谢
S.Naveen ...
Hi all,
Develop an algorithm in C# to give exact change(money) for a Purchase.
INDIAN RUPEES.
The Input is the Change in Rupees.
The Output is the number of Coins & Notes.
Assume that the Coins are Re.1,Rs.2.
The Notes are 5,10,20,50,100,500,1000.Which are our Indian Rupee notes.
Please help on this issue
Thanks in advance
S.Naveen...
推荐答案
这是一个真正的初学者类型问题.
您的算法将要求您以最高音符开头.
您将需要某种循环.用未到期的票据除以有效的票据,例如1500/1000 = 1.5,因此需要1 x 1000票据.
剩余的(0.5)乘以100得到500.除以500,例如500/500 = 1,因此需要1 x 500的音符.
最终结果是您将需要1 x 1000笔记和1 x 500笔记.
This is a real beginner type question.
Your algorithm will require that you start with the highest value note.
you will need a loop of some sort. Divide the amount outstanding by the note valid e.g 1500 / 1000 = 1.5 therefore you requre 1 x 1000 note.
The remained (0.5) is multiplied by 100 giving your 500. Divide that by 500 e.g 500 / 500 = 1 therefore you require 1 x 500 note.
Final result is you will need 1 x 1000 note and 1 x 500 note.
这篇关于在C#中开发一种算法,以给出购买的确切变化(金额)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文