viết chương trình pascal

M

megamanxza

Mã:
[FONT="Times New Roman"][SIZE="4"][COLOR="Blue"][B]Uses crt;
var i: integer;
function KT(so: integer): boolean;
var j: integer;
  begin
    j:=2;
    while so mod j <> 0 do inc(j);
    if j=so then KT:=True else KT:=False;
  end;
begin
clrscr;
write ('Cac so nguyen to tu 1 toi 100: ');
for i:= 1 to 100 do
  if KT(i)=True then write (i,' ');
readln
end.[/B][/COLOR][/SIZE][/FONT]
 
H

huutoan00

Mã:
uses crt;
var M :array [2..100] of boolean;
   
procedure DatSo;
var i:integer;
begin
for i:=4 to 100 do
 begin
  if i mod 2 =0 then m[i]:=false;
  if i mod 3 =0 then m[i]:=false; 
  if i mod 5 =0 then m[i]:=false;
  if i mod 7 =0 then m[i]:=false;
 end;
end;

procedure PrintResult;
var i:integer;
Begin
 for i:=2 to 100 do
  begin
   if m[i] then write(i:2);
  end;
end;

BEGIN
fillchar(m,sizeof(m),true);
DatSo;
m[2]:=true;m[3]:=true;m[5]:=true;m[7]:=true;
PrintResult;
readln
END.
 
Last edited by a moderator:
T

thanhphuong8100

Mã:
program so_nguyen_to;
uses crt;
var i,t,j,d : integer;
begin
    clrscr;
    for i:=2 to 100 do begin
      t:=0;
      for j:=2 to i-1 do if i mod j=0 then inc(t);
      if t=0 then write(i:4);
    end;
    readln;
end.
 
Top Bottom