-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprimeNumber.cs
More file actions
60 lines (48 loc) · 1.17 KB
/
Copy pathprimeNumber.cs
File metadata and controls
60 lines (48 loc) · 1.17 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
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace primeNumber
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("Enter number:" );
int num = Console.ReadLine();
Console.WriteLine(IsPrime(num));
}
public static bool IsPrime(int n)
{
if (n <= 1)
return false;
if (n == 2)
return true;
if (n == 3)
return true;
bool isEven;
if (n % 2 == 0)
isEven = true;
else
isEven = false;
int counter = 3;
double max = Math.Sqrt(n);
bool result = true;
if (isEven == false)
{
do
{
if (n % counter == 0)
result = false;
counter++;
} while (counter <= max);
}
else
{
result = false;
}
return result;
}
}
}