Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Computing the number of coin combinations?
Hello!

I want to solve the following problem with Fortran:

I want to compute the number of combinations for builing a concret amount of
money with coins, e.g. 5 Euros with 2/1/0.5/0.2/0.1/0.05/0.02/0.01 coins.

Is there a simple way to do that?

With thanks

Yours Gernot

Report this thread to moderator Post Follow-up to this message
Old Post
Gernot Pfanner
10-31-04 08:56 PM


Re: Computing the number of coin combinations?
Below I use 0.01 Euros as the unit, so that all coins are integer-valued.
The output:

D:\test>changeways
6295434

-------------- changeways.f90 --------------
program test
print *,changeways((/1,2,5,10,20,50,100,200/), 500)
contains

recursive integer function changeways(coinlist, amount) result(c)
integer, intent(in) :: coinlist(:), amount
integer :: coin, n, i

coin = coinlist(1)
if (amount == 0) then
c = 1
elseif (size(coinlist) == 1) then
if (mod(amount, coin) == 0) then
c = 1
else
c = 0
endif
else
n = amount/coin
c = 0
do i=0,n
c = c + changeways(coinlist(2:), amount-i*coin)
enddo
endif
end function changeways

end program test
----------- end changeways.f90 ------------


"Gernot Pfanner" <pfannerg@stud.uni-graz.at> wrote in message
 news:41850e93$0$31856$91cee783@newsreade
r01.highway.telekom.at...
> Hello!
>
> I want to solve the following problem with Fortran:
>
> I want to compute the number of combinations for builing a concret amount
of
> money with coins, e.g. 5 Euros with 2/1/0.5/0.2/0.1/0.05/0.02/0.01 coins.
>
> Is there a simple way to do that?
>
> With thanks
>
> Yours Gernot



Report this thread to moderator Post Follow-up to this message
Old Post
Matthew Halfant
10-31-04 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Fortran archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:29 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.