Somme
Résolu
xman
-
xman -
xman -
Bonjour,
S'il vous plait aidez moi , je ne sais pas où est l'erreur dans cette procédure
procedure somme(mat:matrice;nc,nl,i,j:integer;var s:integer);
begin
s:=0;
if i<=nl then
if j<= nc then
begin
s:=s+mat[i,j];
somme(mat,nc,nl,i,j+1,s);
end
else
somme(mat,nc,nl,i+1,1,s);
end;
Merci d'avance
S'il vous plait aidez moi , je ne sais pas où est l'erreur dans cette procédure
procedure somme(mat:matrice;nc,nl,i,j:integer;var s:integer);
begin
s:=0;
if i<=nl then
if j<= nc then
begin
s:=s+mat[i,j];
somme(mat,nc,nl,i,j+1,s);
end
else
somme(mat,nc,nl,i+1,1,s);
end;
Merci d'avance
A voir également:
- Somme
- Formule somme excel colonne - Guide
- Somme si couleur - Guide
- Somme en anglais excel - Guide
- Somme si ens date comprise entre ✓ - Forum Excel
- Erreur de somme de contrôle - Forum Logiciels
program matr;
uses wincrt;
type
Matrice=array[1..20,1..20]of integer;
var
Mat:Matrice;
l,c,nl,nc,s:integer;
Procedure Saisie(var nl,nc:integer);
begin
writeln('Donner le nombre de lignes');
readln(nl);
writeln('Donner le nombre de colonnes');
readln(nc);
end;
Procedure Remplissage_Mat(var Mat:Matrice;nc,nl,i,j:integer);
begin
if i<=nl then
if j<=nc then
begin
write('Donner Mat[',i,',',j,'] ');
readln(Mat[i,j]);
remplissage_mat(mat,nc,nl,i,j+1);
end
else
remplissage_mat(mat,nc,nl,i+1,1);
end;
procedure affiche (mat:matrice;nc,nl:integer);
var
i,j:integer;
begin
for i:=1 to nl do
begin
writeln;
for j:=1 to nc do
write(Mat[i,j]:4);
end;
end;
procedure somme(mat:matrice;nc,nl,i,j:integer;var s:integer);
begin
s:=0;
if i<=nl then
if j<= nc then
begin
s:=s+mat[i,j];
somme(mat,nc,nl,i,j+1,s);
end
else
somme(mat,nc,nl,i+1,1,s);
end;
BEGIN
{$M 63000,000}
saisie(nl,nc);
remplissage_mat(mat,nc,nl,1,1);
clrscr;
affiche(mat,nc,nl);
writeln;
somme(mat,nc,nl,1,1,s);
write(s);
end.
Remarque : normalement la récursivité se fait en diminuant la difficulté (donc en diminuant la taille de la matrice au fur et à mesure) alors que ta récursivité l'augmente.
Du coup tu as beaucoup de paramètres à gérer, alors qu'on pourrait en avoir beaucoup moins :
Remarque : il y a une manière itérative évidente pour faire ce calcul :
Exemple de programme de test :