Waliullah8328

Gredy Coin Change

Jul 25th, 2021
700
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. //Gredy Coin Change
  3. int main() {
  4.     // Coin value sorted
  5.     // All value make is possible
  6.    
  7.     int no_of_coin = 4;
  8.     int coins[4] = {2,3,5,10};
  9.     int value = 26;
  10.     int min_coin = 0;
  11.    
  12.     for(int i = 3; i>=0; i--)
  13.     {
  14.         if(value == 0) break;
  15.         if(value >= coin[i])
  16.         {
  17.             min_coin = min_coin + (int)(value / coin[i]);
  18.             value = value % coin[i];
  19.         }
  20.        
  21.     }
  22.    
  23.     if(value == 0)
  24.         printf("%d\n", min_coin);
  25.     else
  26.         printf("Greedy says not possible\n");
  27.    
  28.     return 0;
  29. }
RAW Paste Data