desislava_topuzakova

2. Списък от четни числа

Mar 13th, 2022
940
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.75 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _2._List_of_Even_numbers
  6. {
  7.     internal class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             string input = Console.ReadLine(); // "3 4 8 5 7 5 2 1"
  12.             List<int> numbers = input.Split(" ")  //масив: ["3", "4", "8", "5", "7", "5", "2", "1"]
  13.                                 .Select(int.Parse) // масив: [3, 4, 8, 5, 7, 5, 2, 1]
  14.                                 .ToList(); // лист: {3, 4, 8, 5, 7, 5, 2, 1}
  15.  
  16.             foreach (int number in numbers)
  17.             {
  18.                 if (number % 2 == 0)
  19.                 {
  20.                     Console.Write(number + " ");
  21.                 }
  22.             }
  23.         }
  24.     }
  25. }
  26.  
Advertisement
Add Comment
Please, Sign In to add comment