Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Numerics;
- using System.Text;
- namespace CSharpDemos
- {
- class Program
- {
- static void Main(string[] args)
- {
- int startNum = int.Parse(Console.ReadLine());
- int endNum = int.Parse(Console.ReadLine());
- if (startNum > endNum)
- {
- Console.WriteLine("(empty list)");
- }
- List<int> primes = new List<int>(PrimesInRange(startNum, endNum));
- string result = string.Join(", ", primes);
- Console.WriteLine(result);
- }
- static List<int> PrimesInRange(int startNum, int endNum)
- {
- List<int> result = new List<int>();
- for (int i = startNum; i <= endNum; i++)
- {
- if (i < 2)
- {
- continue;
- }
- bool isPrime = true;
- for (int j = 2; j <= Math.Sqrt(i); j++)
- {
- if (i % j == 0)
- {
- isPrime = false;
- break;
- }
- }
- if (isPrime)
- {
- result.Add(i);
- }
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment