about summary refs log tree commit diff
path: root/usth/ICT2.1/labwork/4/Ex4.c
diff options
context:
space:
mode:
Diffstat (limited to 'usth/ICT2.1/labwork/4/Ex4.c')
-rw-r--r--usth/ICT2.1/labwork/4/Ex4.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/usth/ICT2.1/labwork/4/Ex4.c b/usth/ICT2.1/labwork/4/Ex4.c
new file mode 100644
index 0000000..86eaabb
--- /dev/null
+++ b/usth/ICT2.1/labwork/4/Ex4.c
@@ -0,0 +1,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;
+}