TheBulgarianWolf

Equal sums- right and left

Oct 16th, 2020 (edited)
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.00 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics.CodeAnalysis;
  4. using System.Linq;
  5. using System.Numerics;
  6.  
  7. namespace SoftuniExercisesWithVariables
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             Console.WriteLine("Enter your array here: ");
  15.             int[] array = Console.ReadLine().Split(" ").Select(int.Parse).ToArray();
  16.             int sumLeft;
  17.             int sumRight;
  18.             for (int i = 0; i < array.Length - 1; i++)
  19.             {
  20.                 sumLeft = 0;
  21.                 sumRight = 0;
  22.                 for(int m = 0; m < i; m++)
  23.                 {
  24.                     sumLeft += array[m];
  25.                 }
  26.                 for(int n = i + 1; n < array.Length; n++)
  27.                 {
  28.                     sumRight += array[n];
  29.                 }
  30.                 if(sumLeft == sumRight)
  31.                 {
  32.                     Console.WriteLine(array[i]);
  33.                 }
  34.             }
  35.         }
  36.     }
  37. }
  38.  
Add Comment
Please, Sign In to add comment