Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Linq;
- class HalfSum
- {
- static void Main()
- {
- byte n = byte.Parse(Console.ReadLine());
- //declare an array storing all entered values
- int[] enteredValues = new int[2*n];
- //fill in the array propting the user for values
- for (int i = 0; i < 2*n; i++)
- {
- enteredValues[i] = int.Parse(Console.ReadLine());
- }
- //declare 2 new arrays. One for the first half of of the enteredValues array and another for the second half
- int[] leftSide = enteredValues.Take(enteredValues.Length / 2).ToArray();
- int[] rightSide = enteredValues.Skip(enteredValues.Length / 2).ToArray();
- int leftSideSum = leftSide.Sum();
- int rightSideSum = rightSide.Sum();
- if (leftSideSum == rightSideSum)
- {
- Console.WriteLine("Yes, sum=" + leftSideSum);
- }
- else if (leftSideSum > rightSideSum)
- {
- Console.WriteLine("No, diff=" + (leftSideSum-rightSideSum));
- }
- else
- {
- Console.WriteLine("No, diff=" + (rightSideSum-leftSideSum));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement