Salve a tutti. Ritorno sul medesimo problema, per il quale la soluzione esatta ( e meglio "leggibile" ), dovrebbe essere quella che riporto di seguito. Desidero tuttavia sollecitare l'aiuto degli amici del Forum, poichè il programma non funziona!!! Ovvero non fornisce risultati corretti a tempo di esecuzione. Sarei molto grato a chiunque di voi, più esperto di me in materia, sapesse fornirmi la versione corretta. Grazie!!!
Di seguito riporto la versione da me elaborata:
codice:
program CalcoloProdottoDiDueMatriciUsandoRecord(input,output);
label 1,99;
const n=10;
bell=07;
type termine= record
riga: integer;
colonna: integer;
val: real;
end;
mat= array[1..n*n]of termine;
var a,b,p,q : mat;
i,j,c,h,k,m,r : integer;
procedure ScriviMatriceUsandoRecord( var q : mat );
begin
writeln('Inserire gli elementi della matrice ciascuno separato da <INVIO>:');
writeln;
for c:=1 to h
do begin
readln(q[c].riga);
readln(q[c].colonna);
readln(q[c].val);
end;
writeln;
writeln;
writeln('La matrice e'':');
writeln;
writeln;
for i:=1 to m
do begin
for j:=1 to m
do for c:=1 to h
do if(q[c].riga=i)and(q[c].colonna=j)
then write(' ',(q[c]).val:2:2,' ');
writeln;
end;
end;{ fine procedura ScriviMatriceUsandoRecord }
procedure ProdottoDiMatriciUsandoRecord( a : mat; b : mat ; var p : mat);
begin
c:=1;
i:=1;
j:=1;
while(c>=1)and(c<=h)
do begin
while(i>=1)and(i<=m)
do begin
while(j>=1)and(j<=m)
do begin
p[c].riga:=i;
p[c].colonna:=j;
p[c].val:=0;
for k:=1 to h
do if(a[k].riga=i)and(b[k].colonna=j)
then for r:=1 to m
do p[c].val:=p[c].val+(a[k].val)*(b[k].val);
j:=j+1;
if j<=m
then goto 1;
end;
i:=i+1;
if j>m then begin
j:=1;
goto 1;
end;
end;
1 : c:=c+1;
end;
writeln;
writeln;
writeln('La matrice prodotto risultante e'':');
writeln;
writeln;
for i:=1 to m
do begin
for j:=1 to m
do for c:=1 to h
do if(p[c].riga=i)and(p[c].colonna=j)
then write(' ',(p[c]).val:4:2,' ');
writeln;
end;
end;{ fine procedura ProdottoDiMatriciUsandoRecord }
{ Corpo del programma }
begin
writeln('-------------------------- Dati di ingresso -----------------------------');
writeln;
writeln;
write('Fornire la dimensione delle due matrici quadrate di ingresso a e b: ');
readln(m);
h:=m*m;
writeln;
if m>10 then begin
writeln(chr(bell),'Errore nei dati di ingresso! - STOP -');
goto 99;
end
else begin
ScriviMatriceUsandoRecord(a);
writeln;
ScriviMatriceUsandoRecord(b);
ProdottoDiMatriciUsandoRecord(a,b,p)
end;
99 :
readln;
end.
Grazie a tutti sin d'ora per l'aiuto che saprete ( ne sono certo!!! ) fornirmi. Ciao!!!