Problem Statement 16: Coin Change
Given a set of coins and a value, find the minimum number of coins to satisfy the given value.
Test Case 1:
Coins: {25, 20, 10, 5}, Value: 50 cents
Used coin: 25 cents
Used coin: 25 cents
Total number of coins: 2
Test Case 2:
Coins: {25, 20, 10, 5}, Value: 73 cents
Used coin: 25 cents
Used coin: 25 cents
Used coin: 20 cents
Used coin: 3 cents
Total number of coins: 4
Code:
-
#include int main { int amount =
50; int coins[] = {25, 20, 10, 5}; int
numCoins = 0;
printf("Amount: %d cents\n", amount);
for (int i = 0; i while (amount >= coins[i]){
amount -= coins 1;
numCoins++;
printf("Used
coin: %d cents\n", coins[i]);
}
printf("Total number of coins: %din", numCoins); return 0; }
Problem Statement 19: -#include #include int i,j,k,... Continue reading "C Programming Algorithms: Coin Change, Knapsack, MST, Shortest Path" »