Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Write a software for an ATM machine in C/C++
- // We have an unlimited amount of 1,5,10,50,100,200,500 RON banknotes
- // Write a program that computes the minimum number of banknotes needed to give
- // the customer the cash requested
- // Input: 750
- // Output 500 1 200 1 50 1
- // Explanation: 750 RON is given out as 1* 500RON + 1*200RON + 1*50RON = 750
- // Input: 235
- // Output 200 1 10 3 5 1
- // Explanation: 235 RON is given out as 1 * 200RON + 3*10 RON + 1*5RON = 235
- // Input: 9999
- // Output 500 119 200 2 50 1 10 4 5 1 1 4
- //Example:
- #include <stdio.h>
- const char name[] = "Francisco José Alonso Ares"; // Please enter your name here
- //const char name[] = "Ion Popescu"; // as such
- void withdraw(int n) {
- // this function computes and prints the result
- // Your code goes here
- int stock[7] = { 500, 200, 100, 50, 10, 5, 1 };
- int given[7] = { 0, 0, 0, 0, 0, 0, 0 };
- int val = n;
- int idx = 0;
- while (val > 0) {
- while (val >= stock[idx]) {
- val -= stock[idx];
- given[idx]+=1;
- }
- if (given[idx] > 0) {
- printf ("%d %d ", stock[idx] , given[idx]);
- }
- idx++;
- }
- }
- int main() {
- withdraw(750); // prints out 500 1 200 1 150 1
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement