rez2

1
Program prime_in_interval; Uses crt; Var a,b,t,i:integer; elem:array[1..10000] of integer; Function Prim(x,y:integer):integer; Var c,d,total,nrdiv:integer; Begin total:=0; For c:=x to y do Begin nrdiv:=0; For d:=1 to c do Begin If c mod d=0 then nrdiv:=nrdiv+1; End; If nrdiv=2 then Begin total:=total+1; elem[total]:=c; End; End; Prim:=total; End; Begin Clrscr; Repeat Write('Introduceti A='); Readln(a); Write('Introduceti B='); Readln(b); Until a<=b; t:=Prim(a,b); Writeln('Intervalul contine ',t,' numere prime.'); Writeln('Acestea sunt:'); For i:=1 to t do Write(elem[i],' '); Readln End.

Upload: costin-damian

Post on 07-Apr-2016

215 views

Category:

Documents


3 download

DESCRIPTION

Rez2

TRANSCRIPT

Page 1: Rez2

Program prime_in_interval;Uses crt;Var a,b,t,i:integer; elem:array[1..10000] of integer;Function Prim(x,y:integer):integer; Var c,d,total,nrdiv:integer; Begin total:=0; For c:=x to y do Begin nrdiv:=0; For d:=1 to c do Begin If c mod d=0 then nrdiv:=nrdiv+1; End; If nrdiv=2 then Begin total:=total+1; elem[total]:=c; End;

End; Prim:=total; End;Begin Clrscr; Repeat Write('Introduceti A='); Readln(a); Write('Introduceti B='); Readln(b); Until a<=b; t:=Prim(a,b); Writeln('Intervalul contine ',t,' numere prime.'); Writeln('Acestea sunt:'); For i:=1 to t do Write(elem[i],' '); ReadlnEnd.