Acasa Tehnologie Afisare numere prime pana la n

Afisare numere prime pana la n

by Dragos Schiopu

programare

>

{Afiseaza toate numerele prime pana la n}
program nrprime;
var n:integer;

function prim(nr:integer):boolean;
var i:integer;
begin
prim:=true;
for i:=2 to trunc(sqrt(nr)) do
if nr mod i=0
then prim:=false;
end;

procedure tipar(i:integer);
begin
if i<=n then
if prim(i)
then
begin
write(i,' ');
tipar(i+1);
end
else tipar(i+1);

end;

begin
write('Dati nr:');
readln(n);
tipar(2);
readln;
end.
{PascalZone.uv.ro}

s-ar putea sa-ti placa