Advertisement
silvana1303

even and odd subtraction / lists

Jun 2nd, 2020
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.70 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4. using System.Numerics;
  5. using System.Text;
  6.  
  7. namespace exampreparation
  8. {
  9.     class exam
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.  
  14.             List<int> numbers = Console.ReadLine().Split().Select(int.Parse).ToList();
  15.  
  16.             List<int> numbersNew = new List<int>();
  17.  
  18.             numbersNew.AddRange(numbers);
  19.  
  20.             numbers.RemoveAll(a => a % 2 == 0);
  21.  
  22.             int evenSum = numbers.Sum();
  23.  
  24.             numbersNew.RemoveAll(a => a % 2 != 0);
  25.  
  26.            int oddSum = numbersNew.Sum();
  27.  
  28.             int output = oddSum - evenSum;
  29.  
  30.             Console.WriteLine(output);
  31.         }
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement