Data type:

Long Long integer

Algorithm:

number_of_ways [30001];

int coin [] = { 50, 25, 10, 5, 1 };

ways [0] = 1;

for ( int i = 0; i < 5; i++ ) {

for ( int j = coin [i]; j < 30001; j++)

ways [j] += ways [j – coin [i]];

}

output: number_of_ways [n]

// where ‘n’ is given number

// this process shud be done b4 starting to take inputs

// we saved the value dynamically in an array named number_of_ways

if (ways [n] > 1) then

There are … ways to produce … cents change.

otherwise

There is only 1 way to produce … cents change.

Another algorithm:

U may notice, there is a series …

or a set of 5 numbers giving u the same values

Example :

for n = [0, 1, 2, 3, 4] = number of way : 1

for n = [5, 6, 7, 8, 9] = number of ways : 2

for n = [10, 11, 12, 13, 14] = number of ways : 4

for n = [15, 16, 17, 18, 19] = number of ways : 6

for n = [20, 21, 22, 23, 24] = number of ways : 9

for n = [25, 26, 27, 28, 29] = number of ways : 13

for n = [30, 31, 32, 33, 34] = number of ways : 18

for n = [35, 36, 37, 38, 39] = number of ways : 24

for n = [40, 41, 42, 43, 44] = number of ways : 31

for n = [45, 46, 47, 48, 49] = number of ways : 39

and so on …

### Like this:

Like Loading...

*Related*

## Published by Shahab

Completed B.Sc in CSE, @United International University, Dhaka.
Currently working as Development Engineer, Android and iOS Application.
View all posts by Shahab