Bài 1: Số nguyên tố là số có 2 ước là 1 và chính nó. Hãy viết chương trình con kiểm tra 1 số nguyên có là số nguyên tố hay không? Yêu cầu: Viết chư
Question
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Answers ( )
#include <iostream>
using namespace std;
bool KTSNT(int x)
{
if(x<2)
return false
; for(int i=2; i<=x/2; i++)
if(x%i==0)
return false;
return true;
}
void main()
{
unsigned int n;
cout<<“Nhap vao so nguyen duong n: “;
cin>>n;
if(KTSNT(n)==true)
cout<< n << ” la so nguyen to!”;
else
cout<< n <<” khong la so nguyen to!”;
cout<<endl;
}