@Don: thanks a lot On Sat, Sep 17, 2011 at 12:28 AM, Don <[email protected]> wrote:
> The algorithm is to count them, looping over the number of quarters > and dimes. Then it is easy to compute the number of nickles which > could be used, and the shortfall is made up with pennies. > It is very common to see a recursive solution, but that is not > necessary or beneficial when the iterative solution is so simple. > Don > > int result = 0; > for(int quarters = 0; quarters <= n; quarters += 25) > for(int dimes = 0; (quarters+dimes) <= n; dimes += 10) > result += 1 + (n-quarters-dimes) / 5; > > On Sep 16, 1:35 pm, prasanth n <[email protected]> wrote: > > Given an infinite number of quarters (25 cents), dimes (10 cents), > nickels > > (5 cents) and pennies (1 cent), write code to calculate the number of > ways > > of representing n cents. > > also do give an algorithm first.. > > > > -- > > *prasanth* > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- *prasanth* -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
