Skip to content

techtrendings.com

Let's explore

Menu
Menu

Program to find best possible denomination of input money

In this program, we will be finding possible denomination of money input from user. In this case we are assuming denomination as 1,5,10,25. For example if input money is 65 then denomination will be 25*2,10*1,5*1. Since we are trying to get best possible denomination such that we have least coins, so will store the denomination in decreasing order. Below is the implementation:

#include <iostream>
using namespace std;

int main()
{
    int denom[] = { 25,10,5,1};
    int money;
    cout << "Enter the money:";
    cin >> money;
    int i = 0,coin;
    int denomlen = sizeof(denom)/sizeof(int);
    if (money <= 0)
    {
      cout << "Money not valid";
      return 0;
    }
    while (money > 0 && i < denomlen)
    {
        if (money > denom[i])
        {
            coin = money/denom[i];
            money = money - coin*denom[i];  
            cout << "\n Number of coins of " <<denom[i] <<" :" << coin;
        }
        i++;
    }
   return 0;
}

If you have any feedback please comment below

Recent Posts

  • Binary Tree Level Order Traversal
  • Print Odd Even in Separate threads in C++| TechTrendings
  • Program to move all zeroes to the end
  • Program to reverse word in a string
  • Find the length of longest substring without repeating characters|techtrendings

Recent Comments

  • Twicsy on Program to find unpaired element in an Array in C++|Leetcode |techtrendings

Archives

  • June 2022
  • May 2022
  • March 2022
  • February 2022
  • January 2022

Categories

  • Algorithm
  • Algorithm
  • C++
  • Design Patterns
  • Multithreading
  • Uncategorized

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Join Our Mailing List for the Latest News and Updates.

© 2022 techtrendings.com | Powered by Superbs Personal Blog theme