simonradev

LeftAndRightSumTwoFors

Jul 29th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 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.             for (int i = 0; i < numbersToRead; i++)
  18.             {
  19.                 int currentNumber = int.Parse(Console.ReadLine());
  20.                 leftSum += currentNumber;
  21.             }
  22.  
  23.             // for loop for rightSum
  24.             int rightSum = 0;
  25.             for (int i = 0; i < numbersToRead; i++)
  26.             {
  27.                 int currentNumber = int.Parse(Console.ReadLine());
  28.                 rightSum += currentNumber;
  29.             }
  30.  
  31.             if (leftSum == rightSum)
  32.             {
  33.                 Console.WriteLine($"Yes, sum = {leftSum}");
  34.             }
  35.             else
  36.             {
  37.                 Console.WriteLine($"No, diff = {Math.Abs(leftSum - rightSum)}");
  38.             }
  39.         }
  40.     }
  41. }
Add Comment
Please, Sign In to add comment