Advertisement
desislava_topuzakova

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

Mar 18th, 2023
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.72 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._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.  
  13. List<int> numbers = input.Split(" ") //["3", "4", "8", "5", "7", "5", "2", "1"]
  14. .Select(int.Parse) // [3, 4, 8, 5, 7, 5, 2, 1]
  15. .ToList(); // {3, 4, 8, 5, 7, 5, 2, 1}
  16.  
  17.  
  18. foreach (int number in numbers)
  19. {
  20. if (number % 2 == 0)
  21. {
  22. Console.Write(number + " ");
  23. }
  24. }
  25. }
  26. }
  27. }
  28.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement