Advertisement
Guest User

Problem 1 – Peace of Cake

a guest
Apr 5th, 2014
256
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. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         decimal numberA = decimal.Parse(Console.ReadLine());
  8.         decimal numberB = decimal.Parse(Console.ReadLine());
  9.         decimal numberC = decimal.Parse(Console.ReadLine());
  10.         decimal numberD = decimal.Parse(Console.ReadLine());
  11.  
  12.         decimal total = (numberA / numberB) + (numberC / numberD);
  13.  
  14.         if (total >= 1)
  15.         {
  16.             Console.WriteLine(Math.Floor(total));
  17.         }
  18.         else
  19.         {
  20.             Console.WriteLine("{0:F22}", total);
  21.         }
  22.  
  23.         decimal denominator = numberB * numberD;
  24.         numberA *= (denominator / numberB);
  25.         numberC *= (denominator / numberD);
  26.  
  27.         Console.WriteLine("{0}/{1}", numberA + numberC, denominator);
  28.     }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement