Viết chương trình in ra màn hình tất cả các số nguyên tố bé hơn hoặc bằng n 22/08/2021 Bởi Madeline Viết chương trình in ra màn hình tất cả các số nguyên tố bé hơn hoặc bằng n
Function ktnt(x:integer):boolean; begin Ktnt:=true; For j:=2 to round(sqrt(n)) do if n mod i =0 then Begin Ktnt:=false; Break; End; end; begin … for i:=1 to n do if ktnt(i)=true then write(i,’ ‘); … end;//nhap xuat tu lam Bình luận
Var n,i:integer; Function nt(x:integer):boolean; Var i:integer; BeginNt:=false; If x<2 then exit; For i:=2 to trunc(sqrt(x)) doIf x mod 2=0 then exit; Nt:=true; BeginWrite(‘nhap n:’); readln(N); For i:=2 to n doIf nt(i) then write(i,’ ‘); Readln End. Bình luận
Function ktnt(x:integer):boolean;
begin
Ktnt:=true;
For j:=2
to round(sqrt(n)) do if n mod i =0 then
Begin
Ktnt:=false;
Break;
End;
end;
begin
…
for i:=1 to n do if ktnt(i)=true then write(i,’ ‘);
…
end;//nhap xuat tu lam
Var n,i:integer;
Function nt(x:integer):boolean;
Var i:integer;
BeginNt:=false;
If x<2 then exit;
For i:=2 to trunc(sqrt(x)) doIf x mod 2=0 then exit;
Nt:=true;
BeginWrite(‘nhap n:’);
readln(N);
For i:=2 to n doIf nt(i) then write(i,’ ‘);
Readln
End.