mirror of
https://github.com/TheAlgorithms/C
synced 2024-11-22 13:31:21 +03:00
Merge pull request #131 from TheAlgorithms/changed_#129
improved the code
This commit is contained in:
commit
eaf48e69fb
BIN
misc/demonetization
Executable file
BIN
misc/demonetization
Executable file
Binary file not shown.
@ -4,20 +4,38 @@
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
int ways(int n, int a[], int k) {
|
||||
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<m; i++) scanf("%d", &coin[i]);
|
||||
int main()
|
||||
{
|
||||
int m;
|
||||
int t;
|
||||
int n;
|
||||
|
||||
int t; scanf("%d", &t);
|
||||
while(t--) {
|
||||
int n; scanf("%d", &n);
|
||||
printf("Number of coins? ");
|
||||
scanf("%d", &m);
|
||||
int coin[m], i;
|
||||
for(i=0; i<m; i++)
|
||||
{
|
||||
printf("coin? ");
|
||||
scanf("%d", &coin[i]);
|
||||
}
|
||||
|
||||
printf("---- your requests --- \n");
|
||||
while(1)
|
||||
{
|
||||
printf("amount? exit(0) ");
|
||||
scanf("%d", &n);
|
||||
if (!n)
|
||||
{
|
||||
break;
|
||||
}
|
||||
printf("%d\n", ways(n, coin, m));
|
||||
}
|
||||
return 0;
|
||||
|
BIN
misc/demonetization.o
Normal file
BIN
misc/demonetization.o
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user