VelizarAvramov

08. Odd Even Sum

Mar 22nd, 2017
100
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. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace _08_OddEvenSum
  8. {
  9.     class OddEvenSum
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int n = int.Parse(Console.ReadLine());
  14.             int evenSum = 0;
  15.             int oddSum = 0;
  16.             for (int i = 0; i < n; i++)
  17.             {
  18.                 int num = int.Parse(Console.ReadLine());
  19.                 if (i % 2 == 0)
  20.                 {
  21.                     evenSum += num;
  22.                 }
  23.                 else
  24.                 {
  25.                     oddSum += num;
  26.                 }
  27.             }
  28.             if (evenSum == oddSum)
  29.             {
  30.                 Console.WriteLine("Yes, sum " + oddSum);
  31.             }
  32.             else
  33.             {
  34.                 Console.WriteLine("No diff " + (Math.Abs(evenSum - oddSum)));
  35.             }
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment