arturParchem

Algorytm wydawana reszty metodą zachłanna z groszami

Apr 8th, 2020
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.66 KB | None | 0 0
  1. #include <iostream>
  2. float wejscie,wyjscie;
  3. int reszta;
  4.         int i=0,L;
  5. using namespace std;
  6. int main()
  7.     {
  8.         int N[]={50000,20000,10000,5000,2000,1000,500,200,100,50,20,10,5,2,1};//w groszach
  9.         cout << "Reszta do wyplacenia: ";
  10.         cin >> wejscie;
  11.         reszta = wejscie * 100;
  12.         while(reszta>0)
  13.         {
  14.             if (reszta>= N[i])
  15.             {
  16.                 L = reszta/N[i];
  17.                 reszta -= N[i]*L;
  18.                 wyjscie = N[i];
  19.                 wyjscie = wyjscie / 100;
  20.                 cout <<"Wydaj "<< wyjscie <<" zl po "<< L<<endl;
  21.             }
  22.             i++;
  23.         }
  24.         return 0;
  25.     }
Add Comment
Please, Sign In to add comment