Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _07.Primes_in_Given_Range
- {
- class Program
- {
- static void Main()
- {
- int num1 = int.Parse(Console.ReadLine());
- int num2 = int.Parse(Console.ReadLine());
- if (num1 < 0 || num2 < 0)
- {
- num1 = 2;
- }
- if (num1 == 0 || num1 == 1)
- {
- num1 = 2;
- }
- if (num1 > num2)
- {
- Console.WriteLine("(empty list)");
- }
- GetPrime(num1, num2);
- }
- static void GetPrime(int num1, int num2)
- {
- if (num1 < 2)
- {
- num1 = 2;
- }
- bool firstPrime = true;
- for (int i = num1; i <= num2; i++)
- {
- bool Prime = true;
- for (int j = 2; j <= Math.Sqrt(i); j++)
- {
- if (i % j == 0)
- {
- Prime = false;
- break;
- }
- }
- if (Prime == true && firstPrime == true)
- {
- Console.Write(i);
- firstPrime = false;
- }
- else if (Prime)
- {
- Console.Write(", ");
- Console.Write(i);
- }
- }
- Console.WriteLine();
- }
- }
- }
Add Comment
Please, Sign In to add comment