Advertisement
TeMePyT

Untitled

May 22nd, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 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 _07.Primes_in_Given_Range
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. int startNum = int.Parse(Console.ReadLine());
  14. int endNum = int.Parse(Console.ReadLine());
  15. Console.WriteLine(string.Join(", ", FindPrimesInRange(startNum, endNum).ToList()));
  16.  
  17. }
  18. static List<int> FindPrimesInRange(int startNum, int endNum)
  19. {
  20. List<int> Primes = new List<int>();
  21.  
  22.  
  23. while (startNum <= endNum)
  24. {
  25. bool IsPrime = true;
  26. double squareRoot = (int)Math.Floor(Math.Sqrt(startNum));
  27. if (startNum < 2)
  28. {
  29. IsPrime = false;
  30. }
  31. for (int i = 2; i <= squareRoot; i++)
  32. {
  33. if (startNum % i == 0)
  34.  
  35. {
  36. IsPrime = false;
  37. }
  38.  
  39. }
  40. if(IsPrime)
  41. {
  42. Primes.Add(startNum);
  43. }
  44. startNum++;
  45. }
  46. return Primes;
  47. }
  48. }
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement