Skip to content

techtrendings.com

Let's explore

Menu
Menu

Program to find best possible denomination of input money

Posted on November 9, 2022November 9, 2022 by Avidlearner

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.

Related

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Recent Posts

  • Implement Trie Data Structure in C++- LeetCode
  • How TLS Works
  • C++ – Factory Design Pattern – Creation Design Pattern
  • C++ – Strategy Design Pattern – Behavioral Design Pattern
  • LFU Cache Implementation – LeetCode

Recent Comments

  • automatically like friends photos on instagram on Program to find unpaired element in an Array in C++|Leetcode |techtrendings
  • Twicsy on Program to find unpaired element in an Array in C++|Leetcode |techtrendings

Archives

  • January 2023
  • November 2022
  • August 2022
  • June 2022
  • May 2022
  • March 2022
  • February 2022
  • January 2022

Categories

  • Algorithm
  • Algorithm
  • C++
  • Design Patterns
  • Multithreading
  • OS Concepts
  • Programming
  • Uncategorized

Meta

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

Join Our Mailing List for the Latest News and Updates.

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