From d2d829db0488c7a80b9cfa0550e871fd43adf347 Mon Sep 17 00:00:00 2001 From: Ashutosh Sharma Date: Sat, 24 Mar 2018 00:27:20 +0530 Subject: [PATCH] Create demonetization.c Ways to dispense currency by ATM machine involving recursion. --- misc/demonetization.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 misc/demonetization.c diff --git a/misc/demonetization.c b/misc/demonetization.c new file mode 100644 index 00000000..b7bf8f10 --- /dev/null +++ b/misc/demonetization.c @@ -0,0 +1,24 @@ +// Recursion problem +//Given the denominations of currencies available in a system, find the number of ways an ATM machine can +//generate notes for an entered amount N. + +#include + +int ways(int n, int a[], int k) { + if(n<0 || k<0) return 0; + if(n == 0) return 1; + if(k == 0) return 0; + return ways(n, a, k-1) + ways(n-a[k-1], a, k); +} + +int main() { + int m; scanf("%d", &m); + int coin[m], i; for(i=0; i