Bài 1
Kiểm tra số nguyên tố
Dữ liệu vào là file int.inp
File dữ liệu ra là out.out
program NTO;
var m:longint;
f: text;
function Ngto(n:longint):boolean;
var i:longint;
begin
if n< 2 then ngto:=false else ngto:=true;
for i:= 2 to trunc(sqrt(n)) do
if n mod i = 0 then
begin
ngto:=false;
break;
end;
end;
begin
assign(f,'E:\Pascal\int.inp'); reset(f);
readln(f,m); close(f);
assign(f,'E:\Pascal\out.out'); rewrite(f);
if ngto(m) then write(f,'La so nguyen to')
else write(f,'Khong phai la so nguyen to');
close(f);
end.
Xem thêm…