--Treppiedi Luigi --Il programma esegue la somma tra due numeri interi positivi --di lunghezza qualsiasi --Fatene buon uso with Ada.Text_IO; use Ada.Text_IO; procedure somma is c,riporto,lung1,lung2,lung_max,diff : INTEGER:=0; numero1,numero2 : STRING(1..100); test : BOOLEAN; procedure controllo(a: STRING;b: INTEGER;test : out BOOLEAN) is begin for i in 1..b loop case a(i) is when '1' => test := true; when '2' => test := true; when '3' => test := true; when '4' => test := true; when '5' => test := true; when '6' => test := true; when '7' => test := true; when '8' => test := true; when '9' => test := true; when '0' => test := true; when others => test := false; end case; exit when test=false; end loop; end controllo; procedure calcolo_risultato is risultato,n1,n2 : STRING(1..lung_max+1); procedure assestamento is begin for i in 1..lung_max+1 loop n1(i):='0'; n2(i):='0'; end loop; if diff >=0 then for i in diff+2..lung_max+1 loop n2(i):=numero2(i-(diff+1)); end loop; for i in 2..lung_max+1 loop n1(i):=numero1(i-1); end loop; else diff:=abs(diff); for i in diff+2..lung_max+1 loop n1(i):=numero1(i-(diff+1)); end loop; for i in 2..lung_max+1 loop n2(i):=numero2(i-1); end loop; end if; end assestamento; procedure s_unita(a,b : INTEGER) is begin c := a+b+riporto; if c > 9 then c := c - 10; riporto := 1; else riporto := 0; end if; end s_unita; function c_numero(a :CHARACTER) return INTEGER is begin case a is when '1' => return 1; when '2' => return 2; when '3' => return 3; when '4' => return 4; when '5' => return 5; when '6' => return 6; when '7' => return 7; when '8' => return 8; when '9' => return 9; when '0' => return 0; when others => return 0; end case; end c_numero; function c_carattere(a :INTEGER) return CHARACTER is begin case a is when 1 => return '1'; when 2 => return '2'; when 3 => return '3'; when 4 => return '4'; when 5 => return '5'; when 6 => return '6'; when 7 => return '7'; when 8 => return '8'; when 9 => return '9'; when 0 => return '0'; when others => return '0'; end case; end c_carattere; begin assestamento; for i in reverse 1..lung_max+1 loop s_unita(c_numero(n1(i)),c_numero(n2(i))); risultato(i):=c_carattere(c); end loop; if risultato(1)='0' then risultato(1):=' '; end if; New_line; Put("Il risultato e' "); Put(risultato); end calcolo_risultato; begin Put("Somma di 2 numeri positivi di lunghezza qualsiasi"); New_line(2); Put("Inserisci il primo numero: "); Get_line(numero1,lung1); controllo(numero1,lung1,test); if test=false then New_line; Put("Ti avevo detto di inserire dei numeri. Sai leggere oppure..."); goto FINE; end if; New_line; Put("Inserisci il secondo numero: "); Get_line(numero2,lung2); controllo(numero2,lung2,test); if test=false then New_line; Put("Ti avevo detto di inserire dei numeri. Sai leggere oppure..."); goto FINE; end if; if lung1 >= lung2 then lung_max := lung1; diff:= lung1-lung2; else lung_max := lung2; diff:= lung1-lung2; end if; calcolo_risultato; <> Put(""); end somma;