Advertisement
social1986

Untitled

Oct 4th, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace task._07
  8. {
  9. class Program
  10. {
  11. public static List<int> PrimesInRange(int startNum, int endNum)
  12. {
  13. var primeNumbers = new List<int>();
  14.  
  15. for (int i = startNum; i <= endNum; i++)
  16. {
  17. if (IsPrime(i))
  18. {
  19. primeNumbers.Add(i);
  20. }
  21. }
  22. return primeNumbers;
  23. }
  24.  
  25. public static bool IsPrime(int inputNumber)
  26. {
  27. bool check = true;
  28.  
  29. for (int j = 2; j <= Math.Sqrt(inputNumber); j++)
  30. {
  31. if ((inputNumber % j) == 0)
  32. {
  33. return false;
  34. }
  35. }
  36. return true;
  37. }
  38. static void Main(string[] args)
  39. {
  40. int firstInput = int.Parse(Console.ReadLine());
  41. int secondInput = int.Parse(Console.ReadLine());
  42. Console.WriteLine(string.Join(", ", PrimesInRange(firstInput, secondInput)));
  43. }
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement