Given an amount of currency, return a vector of this form:
[100 50 20 10 5 2 1 0.5 0.25 0.1 0.05 0.01]
Example:
Input a = 257.68
Output b is [2 1 0 0 1 1 0 1 0 1 1 3]
Always use bigger bills/coins if possible.
Solution Stats
Problem Comments
9 Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers3484
Suggested Problems
-
5035 Solvers
-
Find the peak 3n+1 sequence value
2567 Solvers
-
Get the elements of diagonal and antidiagonal for any m-by-n matrix
513 Solvers
-
Split a string into chunks of specified length
2058 Solvers
-
Flip the vector from right to left
10777 Solvers
More from this Author96
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
whoa..rounding error uncovered
Also, "round(X,N)" gives an error - almost like it couldn't have a 2nd parameter
Great problem, not too hard but required a bit of thinking
It took me a long time (before reading the comments !!!) to figure out that for instance the result for rem(135.01,100) is not 35.01 but is 35.009999999999991.
Can anyone help me with why the issue is there and how to solve it (not by adding 1e-3)!?
good job! i enjoyed solving this code
I cannot understand this problem. what means?
Why function roundn is undefined?
A lot of people are adding an amount smaller than a cent to the input to get around floating point issues. There are two other ways to get around this. One is to make the last cent 0.00999 instead. The other is to change your comparison line to compare against a slightly smaller/larger value.
my first floating point issue, yay