-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcoin.c
More file actions
52 lines (43 loc) · 900 Bytes
/
coin.c
File metadata and controls
52 lines (43 loc) · 900 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
int main()
{
int m[10][10];
int d[10];
int i,j,y,n,min;
printf("enter the number of coins\n");
scanf("%d",&n);
printf("enter the value\n");
scanf("%d",&y);
for(i=1;i<=3;i++)
{
scanf("%d",&d[i]);
}
for(j=0;j<=y;j++)
{
m[n][j]=j;
}
for(i=(n-1);i>=1;i--)
{
for(j=0;j<=y;j++)
{
if(d[i]>j)
{
m[i][j]=m[i+1][j];
}
else
{
if(m[i+1][j]<(1+m[i][j-d[i]]))
{
min=m[i+1][j];
}
else
{
min=(1+m[i][j-d[i]]);
}
m[i][j]=min;
}
}
}
printf("%d",m[1][y]);
return 0;
}