SHARE
TWEET

Evens or Odds

a guest Jun 10th, 2016 219 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. namespace _04.FindEvensOrOdds
  5. {
  6.     class EvensOrOdds
  7.     {
  8.         static void Main()
  9.         {
  10.             string[] numbers = Console.ReadLine().Split(' ');
  11.             int startNum = int.Parse(numbers[0]);
  12.             int endNum = int.Parse(numbers[1]);
  13.             string numType = Console.ReadLine();
  14.  
  15.             int divideresult = 0;
  16.             if (numType == "odd")
  17.             {
  18.                 divideresult = 1;
  19.             }
  20.  
  21.             List<int> list = new List<int>();
  22.             for (int i = startNum; i <= endNum; i++)
  23.             {
  24.                 list.Add(i);
  25.             }
  26.  
  27.             List<int> filteredList = Filter(list, n => n % 2 == divideresult);
  28.  
  29.             Console.WriteLine(string.Join(" ", filteredList));
  30.         }
  31.  
  32.         private static List<int> Filter(List<int> list, Predicate<int> pred)
  33.         {
  34.             List<int> result = new List<int>();
  35.             foreach (var num in list)
  36.             {
  37.                 if (pred(num))
  38.                 {
  39.                     result.Add(num);
  40.                 }
  41.             }
  42.  
  43.             return result;
  44.         }
  45.     }
  46. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top