-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem3PrimesInGivenRange
More file actions
50 lines (50 loc) · 1.18 KB
/
Problem3PrimesInGivenRange
File metadata and controls
50 lines (50 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Problem3PrimesInGivenRange
{
static bool IsPrime(int n)
{
bool isPrime = true;
if (n >= 2)
{
for (int i = 2; i <= Math.Sqrt(n); i++)
{
if (n % i == 0)
{
isPrime = false;
break;
}
}
}
else
{
isPrime = false;
}
return isPrime;
}
static List<int> FindPrimesInRange(int startNum, int endNum)
{
List<int> PrimesInRange = new List<int>();
for (int i = startNum; i <= endNum; i++)
{
if (IsPrime(i) == true)
{
PrimesInRange.Add(i);
}
}
return PrimesInRange;
}
static void Main()
{
while (true)
{
int startNum = int.Parse(Console.ReadLine());
int endNum = int.Parse(Console.ReadLine());
string toPrint = String.Join(", ",FindPrimesInRange(startNum, endNum));
Console.WriteLine(toPrint);
}
}
}