By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,148 Members | 779 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,148 IT Pros & Developers. It's quick & easy.

how find no of 100 ,50,20,10,5,2,1 in a given number

P: n/a


hi

i have one problem suppose if we given a number 163 as
input the out put of the number is
one --100
one--- 50
one---10
one-- 2
one--1

plese help me urgent
regards
stalin



Jan 29 '08 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Jan 29, 3:28*pm, stalin <stalin1...@gmail.comwrote:
*hi

* * * * * * *i have one problem suppose if we given a number163 as
input the out put of the number is
* * * * * * * * * * * * * *one --100
* * * * * * * * * * * * * one--- 50
* * * * * * * * * * * * * *one---10
* * * * * * * * * * * * * * * one-- 2
* * * * * * * * * * * * * * * * * one--1
Try something like:

var computeUnits = (function(){

var units = [1, 2, 5, 10, 20, 50, 100];

return {
doBreakdown: function(amt) {
var breakDown = {},
i = units.length,
unit;
while (i--) {
unit = units[i];
breakDown[unit] = (amt/unit)|0;
amt = amt % unit;
}
return breakDown;
},

// Shows how many of each unit
showBreakdown: function(amt) {
var o = this.doBreakdown(amt);
var t = [];
for (var p in o){
t.push(p+': '+o[p]);
}
alert(t.join('\n'));
},

// Shows how many of each unit 0
showBreakdownMin: function(amt) {
var o = this.doBreakdown(amt);
var t = [];
for (var p in o){
if (o[p] 0) {
t.push(p+': '+o[p]);
}
}
alert(t.join('\n'));
}
};
})();

computeUnits.showBreakdown(163);
computeUnits.showBreakdownMin(163);

--
Rob
Jan 29 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.