diff options
author | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2019-12-28 21:16:58 +0700 |
---|---|---|
committer | Nguyễn Gia Phong <vn.mcsinyx@gmail.com> | 2019-12-28 21:21:44 +0700 |
commit | 0887d8f96950a060a122e14ed2981182ff1eb37d (patch) | |
tree | 68be7a59c323c1fd901455ffae8f21874c4bb4c6 /usth/ICT2.1/labwork/4/Ex4.c | |
parent | e461df7573c2b7b7e26c965d8cf2d8e175d67378 (diff) | |
download | cp-0887d8f96950a060a122e14ed2981182ff1eb37d.tar.gz |
[usth/ICT2.1] Algorithm and Data Structures
Diffstat (limited to 'usth/ICT2.1/labwork/4/Ex4.c')
-rw-r--r-- | usth/ICT2.1/labwork/4/Ex4.c | 34 |
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; +} |