Advertisement
dragonbs

Left and Right Sum

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