Venciity

[SoftUni C# exam preparation] 01.PeaceOfCake

Apr 6th, 2014
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class Program
  8. {
  9.     static void Main(string[] args)
  10.     {
  11.         ulong a = ulong.Parse(Console.ReadLine());
  12.         ulong b = ulong.Parse(Console.ReadLine());
  13.         ulong c = ulong.Parse(Console.ReadLine());
  14.         ulong d = ulong.Parse(Console.ReadLine());
  15.  
  16.         ulong denominator = b * d;
  17.  
  18.         a = a * d;
  19.         c = c * b;
  20.  
  21.         ulong sum = a + c;
  22.         decimal result = (a + c) / denominator;
  23.  
  24.         if (result >= 1)
  25.         {
  26.  
  27.             Console.WriteLine(result);
  28.             Console.WriteLine("{0}/{1}", sum, denominator);
  29.         }
  30.         else
  31.         {
  32.             decimal num = (Convert.ToDecimal(a) + Convert.ToDecimal(c)) / Convert.ToDecimal(denominator);
  33.             Console.WriteLine("{0:0.0000000000000000000000}", num);
  34.             Console.WriteLine("{0}/{1}", sum, denominator);
  35.         }
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment