Advertisement
knikolov98

Untitled

Oct 2nd, 2019
118
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.  
  3. namespace Left_and_Right_sum
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int num = int.Parse(Console.ReadLine());
  10.             int leftSum = 0;
  11.             int rightSum = 0;
  12.             int currentNumber = 0;
  13.  
  14.             for (int i = 0; i < num; i++)
  15.             {
  16.                 currentNumber = int.Parse(Console.ReadLine());
  17.                 leftSum += currentNumber;
  18.             }
  19.  
  20.             for (int i = 0; i < num; i++)
  21.             {
  22.                 currentNumber = int.Parse(Console.ReadLine());
  23.                 rightSum += currentNumber;
  24.             }
  25.  
  26.             if (rightSum == leftSum)
  27.             {
  28.                 Console.WriteLine($"Yes, sum = {leftSum}");
  29.             }
  30.             else
  31.             {
  32.                 int diff = rightSum - leftSum;
  33.  
  34.                 Console.WriteLine($"No, diff = {Math.Abs(diff)}");
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement