Tin học Phần mền kiểm tra số nguyên tố viết bằng pascal

huydiu2022

Học sinh mới
Thành viên
6 Tháng chín 2022
5
8
6
17
Nghệ An
program kiem_tra_nguyen_to;
uses crt;
var x,i:integer;
begin
clrscr;
writeln('nhap so:'); readln(x);
if x<= 1 then write(x,' khong phai la so nguyen to')
else
begin
if x<4 then write(x,' la so nguyen to');
i:=2;
while (i<round(sqrt(x))) and ( x mod i<>0) do i:=i+1;
if i> round(sqrt(x)) then write(x,' la so nguyen to') else write(x,' khong phai la so nguyen to');
end;
readln;
end.

bạn tham khảo nhé!
Bạn tham khảo thêm tại: Trọn bộ kiến thức
 

Nam-Nguyễn

Học sinh mới
Thành viên
7 Tháng chín 2022
19
6
6
15
Vĩnh Phúc
program kiem_tra_nguyen_to;
uses crt;
var x,i:integer;
begin
clrscr;
writeln('nhap so:'); readln(x);
if x<= 1 then write(x,' khong phai la so nguyen to')
else
begin
if x<4 then write(x,' la so nguyen to');
i:=2;
while (i<round(sqrt(x))) and ( x mod i<>0) do i:=i+1;
if i> round(sqrt(x)) then write(x,' la so nguyen to') else write(x,' khong phai la so nguyen to');
end;
readln;
end.

bạn tham khảo nhé!
Bạn tham khảo thêm tại: Trọn bộ kiến thức
huydiu2022//C++
#include <bits/stdc++.h>
using namespace std;
string nt(int n)
{
if (n<2)
return "NO";
for (int i=2;i<=n;i++)
if (n%2==0)
return "NO";
return "YES";
}
int main()
{
int n;
cin>>n;
cout<<nt(n);
return 0;
}
 
Top Bottom