VOOZH about

URL: https://www.geeksforgeeks.org/c/c-program-coin-change/

⇱ C Program Coin Change - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

C Program Coin Change

Last Updated : 23 Jul, 2025

Given a value N, if we want to make change for N cents, and we have infinite supply of each of S = { S1, S2, .. , Sm} valued coins, how many ways can we make the change? The order of coins doesn\'t matter.
For example, for N = 4 and S = {1,2,3}, there are four solutions: {1,1,1,1},{1,1,2},{2,2},{1,3}. So output should be 4. For N = 10 and S = {2, 5, 3, 6}, there are five solutions: {2,2,2,2,2}, {2,2,3,3}, {2,2,6}, {2,3,5} and {5,5}. So the output should be 5. 
 

Output:

4


Time Complexity: O(mn) 
Following is a simplified version of method 2. The auxiliary space required here is O(n) only. 

[tabby title=C

Please refer complete article on Dynamic Programming | Set 7 (Coin Change) for more details!

Comment
Article Tags: