Posted By

kcorless on 06/02/18


Tagged

change


Versions (?)

C to make change


 / Published in: C
 

Code to calculate how many ways to make change for n Dollars

  1. #include <stdio.h>
  2.  
  3. int main() {
  4.  
  5. int target = 1000;
  6. int ways = 0;
  7.  
  8. for (int a = target; a >= 0; a -= 100) {
  9. for (int b = a; b >= 0; b -= 50) {
  10. for (int c = b; c >= 0; c -= 25) {
  11. for (int d = c; d >= 0; d -= 10) {
  12. for (int e = d; e >= 0; e -= 5) {
  13. ways++;
  14. }
  15. }
  16. }
  17. }
  18. }
  19. printf("%i dollar can be generated in %i number of ways", target/100, ways);
  20. }

Report this snippet  

You need to login to post a comment.