about summary refs log tree commit diff
path: root/usth/ICT2.1/labwork/4/Ex4.c
blob: 86eaabb7bab678a0e965e71e92f03f4d87a21fb4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/*
 * Exchange money from stdin to least number of 1, 2, 5, 10, 20 and 50 bills.
 * This is free and unencumbered software released into the public domain.
 */

#include <stdio.h>

struct change {
	unsigned amount, bill;
};

const unsigned BILLS[] = {50, 20, 10, 5, 2, 1, 0};

void print_exchange(unsigned money, const unsigned *bills)
{
	if (!*bills)
		return;
	if (*bills > money) {
		print_exchange(money, bills + 1);
		return;
	}
	printf("%u %u\n", money / *bills, *bills);
	print_exchange(money % *bills, bills + 1);
}

int main()
{
	unsigned n;

	scanf("%u", &n);
	print_exchange(n, BILLS);

	return 0;
}