-
-
Save ngnguyen1/5508175 to your computer and use it in GitHub Desktop.
Kiểm tra số nguyên tố.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
class Ngto { | |
public Boolean CheckNT (int n) { | |
bool t = false; | |
if (n > 1) { | |
t = true; | |
for (int i = 2; i <= Math.Sqrt(n); i++) | |
{ | |
if (n % i == 0) | |
{ | |
t = false; | |
break; | |
} | |
} | |
} | |
if (t) | |
{ | |
return true; | |
} else | |
return false; | |
} | |
} | |
class Bai6 { | |
public static void Main(String[] args) { | |
Ngto nt = new Ngto(); | |
do { | |
Console.Write("Nhap n: "); | |
n = int.Parse(Console.ReadLine()); | |
} while (n <= 2 || n >= 100) | |
if (nt.CheckNT(n)) | |
{ | |
Console.WriteLine("{0} la so nguyen to", n); | |
} else | |
Console.WriteLine("{0} khong phai so nguyen to", n); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment