Sử dụng NNLT PASCAL để viết chương trình thực hiện một số công việc với số 19: 1. Nhập vào số nguyên dương N (0<n<1000), khởi tạo ngẫu nhiên mảng gồm N số nguyên dương Ai (0<Ai<2019) (dùng hàm random để khởi tạo) 2. Đếm xem trong dãy cí bao nhiêu số 19? 3. In ra màn hình các số là bội của 19? 4. Số 19 là một số nguyên tố, hãy in ra màn hình các số cùng loại với số 19?

2 câu trả lời

program hotrotinhoc;

var i,n,d: integer;

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

function nt(x: integer): boolean;

var j: integer;

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

readln(n);

d:=0;

for I:=1 to n do

begin

randomize;

a[i]:=random(2019);

end;

for i:=1 to n do

if a[i]=19 then inc(d);

writeln('Trong day co ',d,' so 19');

write('Cac so la boi cua 19 :');

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

writeln;

write('Cac so cung loai voi 19 la :');

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

readln

END.

USES CRT;

var a: array[1..100] of integer;

s,n,i,dem: integer;

Const Max = 500;   

Function NT(n:integer):boolean;

Var i:integer;

Begin  

If (n=0) Or (n=1) then NT:=False  

Else Begin  

i:=2;

While (n mod i <> 0) and (i<Sqrt(n)) do i:=i+1;   

If i>Sqrt(n) then NT:=True

Else Nt:=False;

End;

End;

begin

randomize;

  clrscr;

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

  for i:=1 to n do a[i]:=random(2020);

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

  for i:=1 to n do if a[i]=19 then inc(dem);

  write('Trong day co: ',dem,' so 19');

  writeln;

  write('Cac so la boi cua 19: ');

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

  writeln;

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

  For i:=1 to n do If NT(A[i]) then write(a[i],'   ');

readln;

end.