Advertisement
pavlinpetkov88

Untitled

Jan 27th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class PrimesInGivenRange
  5. {
  6. public static void Main()
  7. {
  8. Console.WriteLine(String.Join(", ", GetNumbers()));
  9.  
  10. }
  11.  
  12. public static int[] GetNumbers()
  13. {
  14. int start = int.Parse(Console.ReadLine());
  15. int end = int.Parse(Console.ReadLine());
  16.  
  17. List<int> list = new List<int>();
  18.  
  19. for (int i = start; i <= end; i++)
  20. {
  21. int isPrime = 0;
  22. for (int j = 1; j < i; j++)
  23. {
  24. if (i % j == 0)
  25. {
  26. isPrime++;
  27. }
  28. if (isPrime == 2)
  29. {
  30. break;
  31. }
  32.  
  33. }
  34. if (isPrime != 2)
  35.  
  36. list.Add(i);
  37. }
  38.  
  39. return list.ToArray();
  40. }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement