Pascal
Résolu
guanaco750
Messages postés
17
Statut
Membre
-
guanaco750 Messages postés 17 Statut Membre -
guanaco750 Messages postés 17 Statut Membre -
Bonjour, je codais un programme dans lequel il y a une comparaison dans un vecteur et mon programme marche bien sauf cette comparaison. Alors j'ai refais un programme test avec juste une comparaison dans un vecteur et je ne comprend pas pour moi il devrait fonctionner. Regarder et dites moi ce qui cloche.
program teste;
type vect = array[1..10] of integer;
var a,b : vect;
c : boolean;
i,j,l : integer;
begin
writeln('Entrez les elements');
for i := 1 to 10 do
begin
write('Element ',i,' : ');
readln(a[i]);
end;
j := 0 ;
c := a[j] > a[j+1];
for j := 1 to 10 do
begin
if a[j] > a[j+1] then b[j] := a[j];
if a[j] < a[j+1] then b[j] := a[j+1];
end;
for l := 1 to 10 do
begin
writeln(b[l]);
end;
readln;
end.
A voir également:
- Pascal
- Turbo pascal - Télécharger - Édition & Programmation
- My pascal - Télécharger - Édition & Programmation
- Dev pascal - Télécharger - Édition & Programmation
- Le protocole assure que la communication entre l'ordinateur de pascal et le serveur de visiodoct est car les informations seront avant d'être envoyées. - Forum Pascal
- Probleme en pascal - Forum Pascal
2 réponses
j := 0 ;
J étant initialisé à 0,
c := a[j] > a[j+1];
est équivalent à:
c := a[0] > a[1];
a étant dimentionné à [1..10]
a[0] est hors limites
Pareil dans le code suivant lors de la dernière itération lorsque J vaut 10:
for j := 1 to 10 do
begin
if a[j] > a[j+1] then b[j] := a[j];
if a[j] < a[j+1] then b[j] := a[j+1];
end;
a[j+1] est alors équivalent à a[11] : hors limite
Enfin un élément de b peut rester non initialisé si a[j] = a[j+1]
J étant initialisé à 0,
c := a[j] > a[j+1];
est équivalent à:
c := a[0] > a[1];
a étant dimentionné à [1..10]
a[0] est hors limites
Pareil dans le code suivant lors de la dernière itération lorsque J vaut 10:
for j := 1 to 10 do
begin
if a[j] > a[j+1] then b[j] := a[j];
if a[j] < a[j+1] then b[j] := a[j+1];
end;
a[j+1] est alors équivalent à a[11] : hors limite
Enfin un élément de b peut rester non initialisé si a[j] = a[j+1]