Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace _7._Prime_Numbers_in_Given_Range
- {
- class Program
- {
- static void Main(string[] args)
- {
- long num1 = long.Parse(Console.ReadLine());
- long num2 = long.Parse(Console.ReadLine());
- if (num1 < 0 || num2 < 0)
- {
- num1 = 2;
- }
- if (num1 == 0 || num1 == 1)
- {
- num1 = 2;
- }
- if (num1 > num2)
- {
- Console.WriteLine("(empty list)");
- }
- for (long i = num1; i < num2; i++)
- {
- bool firstPrime = true;
- bool prime = true;
- if (i > 1)
- {
- for (int j = 2; j < 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