Last active
February 22, 2016 05:51
-
-
Save sjsakib/49ea7dc8dbd5b18f8e0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int coin[] = {50,20,10,5,2,1}; | |
int return_change(int amount) { | |
int res = 0; | |
int j = 0; | |
while(amount>0) { | |
if(amount<=coin[j]) { | |
amount-=coin[j]; | |
res++; | |
} else { | |
if(j == 6) { //নোট বা কয়েন শেষ কিন্তু টাকা শেষ হয়নি। তাহলে ভাংতি দেয়া যাবে না | |
res = -1; | |
break; | |
} else { | |
j++; | |
} | |
} | |
} | |
cout<<res; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment