Advertisement
Guest User

Basics Exam 10 April 2014 Morning 02.Half Sum

a guest
Jun 1st, 2014
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. class HalfSum
  8. {
  9.     static void Main()
  10.     {
  11.         int n, firstNumber, secondNumber;
  12.         int firstSum = 0;
  13.         int secondSum = 0;
  14.         do
  15.         {
  16.             n = int.Parse(Console.ReadLine());
  17.         } while ((n >= 0)^(n <= 500));
  18.         for (int i = 0; i < n; i++)
  19.         {
  20.             do
  21.             {
  22.                 firstNumber = int.Parse(Console.ReadLine());
  23.             } while ((firstNumber >= -500000)^(firstNumber <= 500000));
  24.             do
  25.             {
  26.                 secondNumber = int.Parse(Console.ReadLine());
  27.             } while ((secondNumber >= -500000) ^ (secondNumber <= 500000));
  28.             firstSum += firstNumber;
  29.             secondSum += secondNumber;
  30.         }
  31.         if (firstSum == secondSum)
  32.         {
  33.             Console.WriteLine("Yes, sum="+ firstSum);
  34.         }
  35.         else
  36.         {
  37.             int difference;
  38.             if (firstSum > secondSum)
  39.             {
  40.                 difference = firstSum - secondSum;
  41.             }
  42.             else
  43.             {
  44.                 difference = secondSum - firstSum;
  45.             }
  46.             Console.WriteLine("No, diff="+difference);
  47.         }
  48.     }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement