Re: Change for a Dollar



Here's the code for finding out the number of ways :

// 292 ways of changing a dollar

#include <stdio.h>

int main()
{
int cn_50, cn_25, cn_10, cn_5, cn_1, c=0;

printf("\n 50 25 10 5 1 ");
printf("\n======================");

for ( cn_50=0; cn_50<=100; cn_50+=50 )
for ( cn_25=0; cn_25<=100; cn_25+=25 )
for ( cn_10=0; cn_10<=100; cn_10+=10 )
for ( cn_5=0; cn_5<=100; cn_5+=5 )
{
cn_1 = 100 - (cn_50+cn_25+cn_10+cn_5);
if ( cn_1>=0 )
{
++c;
printf("\n%4d%4d%4d%4d%5d",
cn_50/50,cn_25/25,cn_10/10,cn_5/5,cn_1);
}
}

printf("\n\nTotal number of ways : %d",c);
}

================================================================
================================================================

and here's the output of the above code :

50 25 10 5 1
======================
0 0 0 0 100
0 0 0 1 95
0 0 0 2 90
0 0 0 3 85
0 0 0 4 80
0 0 0 5 75
0 0 0 6 70
0 0 0 7 65
0 0 0 8 60
0 0 0 9 55
0 0 0 10 50
0 0 0 11 45
0 0 0 12 40
0 0 0 13 35
0 0 0 14 30
0 0 0 15 25
0 0 0 16 20
0 0 0 17 15
0 0 0 18 10
0 0 0 19 5
0 0 0 20 0
0 0 1 0 90
0 0 1 1 85
0 0 1 2 80
0 0 1 3 75
0 0 1 4 70
0 0 1 5 65
0 0 1 6 60
0 0 1 7 55
0 0 1 8 50
0 0 1 9 45
0 0 1 10 40
0 0 1 11 35
0 0 1 12 30
0 0 1 13 25
0 0 1 14 20
0 0 1 15 15
0 0 1 16 10
0 0 1 17 5
0 0 1 18 0
0 0 2 0 80
0 0 2 1 75
0 0 2 2 70
0 0 2 3 65
0 0 2 4 60
0 0 2 5 55
0 0 2 6 50
0 0 2 7 45
0 0 2 8 40
0 0 2 9 35
0 0 2 10 30
0 0 2 11 25
0 0 2 12 20
0 0 2 13 15
0 0 2 14 10
0 0 2 15 5
0 0 2 16 0
0 0 3 0 70
0 0 3 1 65
0 0 3 2 60
0 0 3 3 55
0 0 3 4 50
0 0 3 5 45
0 0 3 6 40
0 0 3 7 35
0 0 3 8 30
0 0 3 9 25
0 0 3 10 20
0 0 3 11 15
0 0 3 12 10
0 0 3 13 5
0 0 3 14 0
0 0 4 0 60
0 0 4 1 55
0 0 4 2 50
0 0 4 3 45
0 0 4 4 40
0 0 4 5 35
0 0 4 6 30
0 0 4 7 25
0 0 4 8 20
0 0 4 9 15
0 0 4 10 10
0 0 4 11 5
0 0 4 12 0
0 0 5 0 50
0 0 5 1 45
0 0 5 2 40
0 0 5 3 35
0 0 5 4 30
0 0 5 5 25
0 0 5 6 20
0 0 5 7 15
0 0 5 8 10
0 0 5 9 5
0 0 5 10 0
0 0 6 0 40
0 0 6 1 35
0 0 6 2 30
0 0 6 3 25
0 0 6 4 20
0 0 6 5 15
0 0 6 6 10
0 0 6 7 5
0 0 6 8 0
0 0 7 0 30
0 0 7 1 25
0 0 7 2 20
0 0 7 3 15
0 0 7 4 10
0 0 7 5 5
0 0 7 6 0
0 0 8 0 20
0 0 8 1 15
0 0 8 2 10
0 0 8 3 5
0 0 8 4 0
0 0 9 0 10
0 0 9 1 5
0 0 9 2 0
0 0 10 0 0
0 1 0 0 75
0 1 0 1 70
0 1 0 2 65
0 1 0 3 60
0 1 0 4 55
0 1 0 5 50
0 1 0 6 45
0 1 0 7 40
0 1 0 8 35
0 1 0 9 30
0 1 0 10 25
0 1 0 11 20
0 1 0 12 15
0 1 0 13 10
0 1 0 14 5
0 1 0 15 0
0 1 1 0 65
0 1 1 1 60
0 1 1 2 55
0 1 1 3 50
0 1 1 4 45
0 1 1 5 40
0 1 1 6 35
0 1 1 7 30
0 1 1 8 25
0 1 1 9 20
0 1 1 10 15
0 1 1 11 10
0 1 1 12 5
0 1 1 13 0
0 1 2 0 55
0 1 2 1 50
0 1 2 2 45
0 1 2 3 40
0 1 2 4 35
0 1 2 5 30
0 1 2 6 25
0 1 2 7 20
0 1 2 8 15
0 1 2 9 10
0 1 2 10 5
0 1 2 11 0
0 1 3 0 45
0 1 3 1 40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 2 5 5
1 0 2 6 0
1 0 3 0 20
1 0 3 1 15
1 0 3 2 10
1 0 3 3 5
1 0 3 4 0
1 0 4 0 10
1 0 4 1 5
1 0 4 2 0
1 0 5 0 0
1 1 0 0 25
1 1 0 1 20
1 1 0 2 15
1 1 0 3 10
1 1 0 4 5
1 1 0 5 0
1 1 1 0 15
1 1 1 1 10
1 1 1 2 5
1 1 1 3 0
1 1 2 0 5
1 1 2 1 0
1 2 0 0 0
2 0 0 0 0

Total number of ways : 292

================================================================
================================================================

Total number of ways = 292 and that's without taking that "single
dollar coin for a change" case into account.

Guess that will put an end to so many postings. I was fed up seeing so
many guys posting on this topic.

.



Relevant Pages

  • Re: peculiar problem with expression evaluation
    ... Here is code snippet ... int i = 5; ... Please see the scores of previous postings about this form of undefined ... The fact is that is covered by the FAQ, but not by you, who as usual; ...
    (comp.lang.c)
  • Re: peculiar problem with expression evaluation
    ... I observed something surprising: ... Here is code snippet ... int i = 5; ... Please see the scores of previous postings about this form of undefined ...
    (comp.lang.c)
  • Re: peculiar problem with expression evaluation
    ... I observed something surprising: ... Here is code snippet ... int i = 5; ... Please see the scores of previous postings about this form of undefined ...
    (comp.lang.c)
  • Mailing list question
    ... I have subscribed this list with an address int the gmail.com domain, ... and I receive your postings there,but it seems I can send messages with THIS address,and I don't receive my messages sent with the gmail account. ... gratis 1GB per i messaggi e allegati da 10MB ...
    (comp.lang.python)
  • Re: Steve Herborn posts attacks from his office computer
    ... account, but because of the times of the postings. ... His use of the company computer for personal business is wrong and may ... He has indeed used several different sockpuppets to attack his enemies. ...
    (alt.support.chronic-pain)