In England the currency is made up of pound, £, and pence, p, and there are eight coins in general circulation:
1p, 2p, 5p, 10p, 20p, 50p, £1 (100p) and £2 (200p).
It is possible to make £2 in the following way:
1×£1 + 1×50p + 2×20p + 1×5p + 1×2p + 3×1p
How many different ways can £2 be made using any number of coins?
int counter = 0; for (int i = 0; i <= 200; i++) {//1 pence for (int j = 0; j <= 100; j++) {//2 pence for (int k = 0; k <= 40; k++) {//5 pence for (int l = 0; l <= 20; l++) {//10 pence for (int m = 0; m <= 10; m++) {//20 pence for (int n = 0; n <= 4; n++) {//50 pence for (int o = 0; o <= 2; o++) {//1 pound for (int p = 0; p <= 1; p++) {//2 pound if ((i*1+j*2+k*5+l*10+m*20+n*50+o*100+p*200)==200) { counter++; } } } } } } } } } System.out.println(counter);
Lösung: 73682