Advertisement
Atanasov_88

Half Sum

Jul 7th, 2015
447
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5.     class ForEachLoopArray
  6.     {
  7.         static void Main()
  8.         {
  9.             int n = int.Parse(Console.ReadLine());
  10.  
  11.             int sumOne = 0;
  12.  
  13.             for (int i = 0; i < n; i++)
  14.             {
  15.                 int element = int.Parse(Console.ReadLine());
  16.  
  17.                 sumOne = sumOne + element;
  18.  
  19.             }
  20.  
  21.             int sumTwo = 0;
  22.  
  23.             for (int i = 0; i < n; i++)
  24.             {
  25.                 int elementTwo = int.Parse(Console.ReadLine());
  26.  
  27.                 sumTwo = sumTwo + elementTwo;
  28.             }
  29.  
  30.             if (sumOne == sumTwo)
  31.             {
  32.                 Console.WriteLine("Yes, sum={0}", sumOne);
  33.             }
  34.             if (sumOne != sumTwo)
  35.             {
  36.                 int diff = Math.Abs(sumOne - sumTwo);
  37.                 Console.WriteLine("No, diff={0}",  diff);
  38.             }
  39.         }
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement