Advertisement
Daniel_007

07. Left and Right Sum

Oct 19th, 2019
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.88 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Left and Right Sum
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int howMany = int.Parse(Console.ReadLine());
  10.             int sumLeft = 0;
  11.             int sumRight = 0;
  12.             int number = 0;
  13.             for (int i = 0; i < 2 * howMany; i++)
  14.             {
  15.                 number = int.Parse(Console.ReadLine());
  16.                 if (i < howMany)
  17.                 {
  18.                     sumLeft += number;
  19.                 }
  20.                 else
  21.                 {
  22.                     sumRight += number;
  23.                 }
  24.             }
  25.             if (sumRight==sumLeft)
  26.             {
  27.                 Console.WriteLine($"Yes, sum = {sumLeft}");
  28.             }
  29.             else
  30.             {
  31.                 Console.WriteLine($"No, diff = {Math.Abs(sumLeft-sumRight)}");
  32.             }
  33.         }
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement