Advertisement
ivanov_ivan

OddAndEvenSum

Aug 18th, 2016
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.10 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 OddAndEvenSum
  8. {
  9.     class OddAndEvenSum
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int count = int.Parse(Console.ReadLine());
  14.  
  15.             var evenSum = 0;
  16.             var oddSum = 0;
  17.  
  18.             for(int i = 0; i < count; i++)
  19.             {
  20.                 int number = int.Parse(Console.ReadLine());
  21.  
  22.                 if(i % 2 == 0)
  23.                 {
  24.                     evenSum += number;
  25.                 }
  26.                 else
  27.                 {
  28.                     oddSum += number;
  29.                 }
  30.             }
  31.  
  32.             if(evenSum == oddSum)
  33.             {
  34.                //Console.WriteLine("Yes");
  35.                //Console.WriteLine("Sum = {0}" , evenSum);
  36.                 Console.WriteLine("Yes\nSum = {0}",evenSum);
  37.             }
  38.             else
  39.             {
  40.                 Console.WriteLine("No");
  41.                 Console.WriteLine("Diff = {0}" , Math.Abs(evenSum - oddSum));
  42.             }
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement