Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace ConsoleApplication10
- {
- class Program
- {
- static bool isPrime(int n)
- {
- bool prime = true;
- if (n == 0 || n == 1)
- prime = false;
- for (int i = 2; i <= n/2; i++)
- {
- if (n % i == 0)
- {
- prime = false;
- }
- else
- {
- prime = true;
- }
- }
- //if (prime) Console.WriteLine("True");
- //else Console.WriteLine("False");
- return prime;
- }
- private static List<int> FindPrimesInRange(int startNum, int endNum)
- {
- var primes = new List<int>();
- for (int currentNum=startNum; currentNum<=endNum; currentNum++)
- {
- if (isPrime(currentNum))
- {
- primes.Add(currentNum);
- }
- }
- return primes;
- }
- static void Main(string[] args)
- {
- var startNum = int.Parse(Console.ReadLine());
- var endNum = int.Parse(Console.ReadLine());
- var primes = FindPrimesInRange(startNum, endNum);
- Console.WriteLine(string.Join(", ",primes));
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement