Coin Change: Minimum number of coins

Problem: You are given n types of coin denominations of values v(1)<v(2)<…<v(n) (all integers). Assume v(1)=1, so you can always make change for any amount of money C. Give an algorithm which makes change for an amount of money C with as few coins as possible. #include <stdio.h> #include <stdlib.h> int main() { int i,n,den[20],temp[20],min,min_idx, … Read more

CS50 Pset1 Greedy, change algorithm

The purpose of the code is to calculate the least amount of coins needed to produce correct amount of change given a dollar or cent user input. I’m just starting out and appreciate any pointers in how this code could/should be optimized. The code works but I feel there is some redundancy with all those … Read more

Dividing an arbitrary dollar amount into the fewest bills and coins

I am taking a class in mobile application development this fall. I have finished my first assignment of creating a class to divide an arbitrary dollar amount into the minimum number of bills and coins. I have completed the assignment and everything works as intended (outside of an occasional error I’m having with computing pennies, … Read more

Vending machine change function

Write a function that takes an amount of money M, a price P and returns the change given in the smallest number of coins. The following coins are available: 1c, 5c, 10c, 25c, 50c, and $1. Time: 20min. I’m looking for all sorts of reviews considering the time limit and environment. Here’s my code: #include … Read more

More optimal “Making Change” Problem: Knapsack challenge

The problem description is: You are given n types of coin denominations of values v(1) < v(2) < … < v(n) (all integers). Assume v(1) = 1, so you can always make change for any amount of money C. Give an algorithm which makes change for an amount of money C with as few coins … Read more