Skip to content

Commit 1935279

Browse files
Create Greedy-PP1.c
1 parent d9aacba commit 1935279

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Greedy-Algorithms/Greedy-PP1.c

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include<stdio.h>
2+
int main()
3+
{
4+
int n,ans=0,i=0;
5+
int a[]={1000,500,100,50,20,10,5,2,1};
6+
scanf("%d",&n);
7+
while(n>0)
8+
{
9+
if(a[i]<=n)
10+
{
11+
n-=a[i];
12+
ans++;
13+
}
14+
else
15+
i++;
16+
}
17+
printf("%d",ans);
18+
}

0 commit comments

Comments
 (0)