Advertisement
desislava_topuzakova

Problem 1.Принадлежи ли дадено число на масив

Jun 6th, 2020
163
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace AlgorithmsOverStructureData
  5. {
  6. class Program
  7. {
  8. static void Main(string[] args)
  9. {
  10. string input = Console.ReadLine(); //"2 3 4 5 6 7"
  11. int[] numbers = input.Split(" ").Select(int.Parse).ToArray();
  12. //["2", "3", ...] -> [2, 3, 4, 5, 6, 7]
  13. int number = int.Parse(Console.ReadLine());
  14.  
  15. foreach(int numberInArray in numbers)
  16. {
  17. if (numberInArray == number)
  18. {
  19. Console.WriteLine($"{number} Exists in the List");
  20. return;
  21. }
  22. }
  23.  
  24. Console.WriteLine($"{number} Not exists in the List");
  25.  
  26. }
  27. }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement