Advertisement
simonradev

LeftAndRightSumOneFor

Jul 29th, 2017
146
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.04 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. namespace LiveDemo
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int numbersToRead = int.Parse(Console.ReadLine());
  14.  
  15.             // for loop for leftSum
  16.             int leftSum = 0;
  17.             int rightSum = 0;
  18.             for (int i = 0; i < numbersToRead * 2; i++)
  19.             {
  20.                 int currentNumber = int.Parse(Console.ReadLine());
  21.  
  22.                 if (i < numbersToRead)
  23.                 {
  24.                     leftSum += currentNumber;
  25.                 }
  26.                 else
  27.                 {
  28.                     rightSum += currentNumber;
  29.                 }
  30.             }
  31.  
  32.             if (leftSum == rightSum)
  33.             {
  34.                 Console.WriteLine($"Yes, sum = {leftSum}");
  35.             }
  36.             else
  37.             {
  38.                 Console.WriteLine($"No, diff = {Math.Abs(leftSum - rightSum)}");
  39.             }
  40.         }
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement