Bài 9. Làm việc với dãy số

VL

Nhập 1 mảng . In ra các phần tử là số nguyên tố

ML
8 tháng 5 2020 lúc 19:37

Program hotrotinhoc_hoc24;

var i,n: integer;

a: array[1..32000] of integer;

function nt(x: longint): boolean;

var j: longint;

begin

nt:=true;

if (x=2) or (x=3) then exit;

nt:=false;

if (x=1) or (x mod 2=0) or (x mod 3=0) then exit;

j:=5;

while (j<=trunc(sqrt(x))) do

begin

if (x mod j=0) or (x mod (j+2)=0) then exit;

j:=j+6;

end;

nt:=true;

end;

begin

write('Nhap so phan tu cua day: '); readln(n);

for i:=1 to n do

begin

write('a[',i,']='); readln(a[i]);

end;

write('Cac so nguyen to co trong mang la : ');

for i:=1 to n do if nt(a[i]) then write(a[i],' ');

readln

end.

Bình luận (0)

Các câu hỏi tương tự
NT
Xem chi tiết
NN
Xem chi tiết
MN
Xem chi tiết
AS
Xem chi tiết
AS
Xem chi tiết
AS
Xem chi tiết
T0
Xem chi tiết
PL
Xem chi tiết
NT
Xem chi tiết
HC
Xem chi tiết