with Ada.Text_IO, Ada.Integer_Text_IO; use Ada.Text_IO, Ada.Integer_Text_IO; procedure eratostene is --------definizione variabili-------------- type NATURALI is array(1..1001) of INTEGER; primo : INTEGER :=2; indice, numero : INTEGER; primi : NATURALI; esci : CHARACTER; begin --------ricerca dei numeri primi----------- primi(1):=0; for i in 2..1000 loop primi(i):=1; end loop; loop indice:=primo; loop indice:=indice+primo; if indice > 1000 then exit; end if; primi(indice):=0; end loop; loop primo:=primo+1; if (primo > 1000)or(primi(primo)=1) then exit; end if; end loop; if primo > 1000 then exit; end if; end loop; for i in 1..1000 loop if primi(i)=1 then Put(i); end if; end loop; --------controllo di un numero a scelta----------- New_Line(2); loop Put("Inserire un numero 1...1000: "); Get(numero); if primi(numero)=1 then Put(numero); Put(" e` un numero primo"); else Put(numero); Put(" non e` un numero primo"); end if; New_line(2); Put("Uscire? s/n: "); Get(esci); exit when (esci='s') or (esci='S'); end loop; end eratostene;