Advertisement
koksibg

08. Odd Even Sum

Oct 24th, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.96 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 Odd_Even_Sum
  8. {
  9.     class Odd_Even_Sum
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int SumOdd = 0;
  14.             int SumEven = 0;
  15.             int n = int.Parse(Console.ReadLine());
  16.             for (int i = 1; i <= n; i++)
  17.             {
  18.                 if (i % 2 == 0)
  19.                 {
  20.                     int NubmerEven = int.Parse(Console.ReadLine());
  21.                     SumEven += NubmerEven;
  22.                 }
  23.                 else
  24.                 {
  25.                     int NubmerOdd = int.Parse(Console.ReadLine());
  26.                     SumOdd += NubmerOdd;
  27.                 }
  28.             }
  29.             int difference = Math.Abs(SumOdd - SumEven);
  30.             if (difference == 0) Console.WriteLine("Yes sum " + SumOdd);
  31.             else Console.WriteLine("No diff " + difference);
  32.         }
  33.     }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement