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

S

stalin

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
 
E

Erwin Moller

stalin said:
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

Hi,

Here is a simple solution.

Regards,
Erwin Moller



<html>
<head>
<title>moneytest</title>
</head>
<body>


<form method="POST" name="testform">
<input type="text" name="someval">
<input type="button" value="split us" onClick="calc();">
</form>
<div id="output"></div>

<script type="text/javascript">
var money = new Array (100 ,50,20,10,5,2,1);
var amount = new Array(0,0,0,0,0,0,0);
var numEl = money.length;
var theDiv = document.getElementById("output");

function calc (){
var aVal = parseInt(document.forms.testform.someval.value,10);
while (aVal > 0){
var theDiv = document.getElementById("output");
for (var i=0;i<numEl;i++){
if (aVal >= money ){
aVal = aVal - money;
amount++;
break;
}
}
}
// output:
theDiv.innerHTML="";
for (var i=0;i<numEl;i++){
addShow(money+" : "+amount+" times");
}

}

function addShow(aStr){
theDiv.innerHTML=theDiv.innerHTML+"<br>"+aStr;
}

</script>

</body>
</html>
 
R

RobG

 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;
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);
 
D

Dr J R Stockton

In comp.lang.javascript message <c5b2342f-98c5-4065-ba9c-67d60bebd3ec@h1
1g2000prf.googlegroups.com>, Mon, 28 Jan 2008 21:28:49, stalin
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

That's been answered adequately. Maybe mod the quantity-in-hand with
the first not-completed coin to get the new q-i-h, and divide the
difference to get the count of that coin. But, in some currencies, that
might not be the optimum division. To change pre-war five-pound note,
it would not be efficient to start with four guineas; four shillings was
better done with two florins than by starting with a half-crown.

It's more interesting to see in how many ways a sum can be split into
coins - see <URL:http://www.merlyn.demon.co.uk/js-misc1.htm#JAD>, in
Cacheing. £1.63 can be split into coin in 30698 ways, using coins 100,
50, 20, 10, 5, 2, 1. Without cacheing it takes me 6 seconds, with
cacheing it is too quick to measure.

regards
stalin

But I have seen your grave; in a flower-bed outside the Kremlin wall,
where you were deposited after being deemed unworthy to remain beside
Vladimir Ilyich.

It's a good idea to read the newsgroup c.l.j and its FAQ. See below.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top