Advertisement
YORDAN2347

Coins

Nov 29th, 2020
660
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Coins
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int[] coins = { 200, 100, 50, 20, 10, 5, 2, 1 };
  10.             double price = double.Parse(Console.ReadLine());
  11.             price *= 100;
  12.             price = Math.Round(price, 0);
  13.  
  14.             int counter = 0;
  15.             int i = 0;
  16.             while(price > 0)
  17.             {
  18.                
  19.                 if (price >= coins[i])
  20.                 {                
  21.                     price -= coins[i];
  22.                     if (price >= coins[i])
  23.                         i--;
  24.                     counter++;
  25.                 }
  26.                 i++;
  27.                
  28.             }
  29.             Console.WriteLine(counter);
  30.         }
  31.     }
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement