desislava_topuzakova

3.Изтриване на отрицателни елементи

Feb 28th, 2021
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Arrays
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11.  
  12. List<int> numbers = Console.ReadLine().Split(" ").Select(int.Parse).ToList();
  13. List<int> positiveNumbers = new List<int>(); // положителните числа
  14.  
  15. foreach(int number in numbers)
  16. {
  17. if(number > 0)
  18. {
  19. positiveNumbers.Add(number);
  20. }
  21. }
  22.  
  23. if(positiveNumbers.Count == 0)
  24. {
  25. Console.WriteLine("Empty");
  26. }
  27. else
  28. {
  29. positiveNumbers.Reverse();
  30. Console.WriteLine(string.Join(" ", positiveNumbers));
  31. }
  32.  
  33.  
  34. }
  35. }
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment