Advertisement
Qrist

Even and Odd Subtraction

Apr 7th, 2020
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.77 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace GitHub
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] num = new int[] { 1, 2, 3, 4, 5, 6 };
  11.             int even = 0;
  12.             int odd = 0;
  13.             for (int i = 0; i < num.Length; i++)
  14.             {
  15.                 Console.Write(num[i]+ " ");
  16.                 if (num[i] % 2 == 0)
  17.                 {
  18.                     even += num[i];
  19.                 }
  20.                 else
  21.                 {
  22.                     odd += num[i];
  23.                 }
  24.             }
  25.             int result = even - odd;
  26.             Console.WriteLine("\nEven: " + even);
  27.             Console.WriteLine("Odd: "+odd);
  28.             Console.WriteLine("Result:" + result);
  29.         }
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement