Skip to content

Instantly share code, notes, and snippets.

@ngnguyen1
Last active December 16, 2015 22:39
Show Gist options
  • Save ngnguyen1/5508175 to your computer and use it in GitHub Desktop.
Save ngnguyen1/5508175 to your computer and use it in GitHub Desktop.
Kiểm tra số nguyên tố.
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