We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fe80dfc commit 84b939fCopy full SHA for 84b939f
20. Dynamic Programming/MakeAChange.c
@@ -0,0 +1,27 @@
1
+//Make a change problem using dynamic programming
2
+//Hasti Sutaria
3
+#include <stdio.h>
4
+int coins( int S[], int m, int n ) {
5
+int i, j, x, y;
6
+int table[n+1][m];
7
+for (i=0; i<m; i++)
8
+table[0][i] = 1;
9
+for (i = 1; i < n+1; i++) {
10
+for (j = 0; j < m; j++) {
11
+x = (i-S[j] >= 0)? table[i - S[j]][j]: 0;
12
+y = (j >= 1)? table[i][j-1]: 0;
13
+table[i][j] = x + y;
14
+}
15
16
+return table[n][m-1];
17
18
+
19
+int main() {
20
+int arr[] = {1,2,5,10};
21
+int m = sizeof(arr)/sizeof(arr[0]);
22
+int n = 15;
23
24
+printf("The total number of combinations of coins that sum up to %d",n);
25
+printf(" is %d ", coins(arr, m, n));
26
+return 0;
27
0 commit comments