Fonction str et val en pascal
oh9007
Messages postés
41
Date d'inscription
Statut
Membre
Dernière intervention
-
oh9007 -
oh9007 -
Bonjour,Aidez moi svp !!
je trouve pas l'erreur !!!(val)!
svp comment utiliser la fonction val ?
program exe;
uses wincrt;
var ch,chi,chp:string; i,nb,x:integer;
begin
write('donner un nombre entier svp :');
read(nb);
str (nb,ch);
for i:=1 to length(ch) do
begin
x:=val(ch[i]);
if x mod 2 = 0 do
chp:=chp+ch[i] else
chi:=chi+ch[i];
end;
writeln('les nombre paires ',chp);
writeln('les nombres impaires ',chi);
readln;readln;
end.
je trouve pas l'erreur !!!(val)!
svp comment utiliser la fonction val ?
program exe;
uses wincrt;
var ch,chi,chp:string; i,nb,x:integer;
begin
write('donner un nombre entier svp :');
read(nb);
str (nb,ch);
for i:=1 to length(ch) do
begin
x:=val(ch[i]);
if x mod 2 = 0 do
chp:=chp+ch[i] else
chi:=chi+ch[i];
end;
writeln('les nombre paires ',chp);
writeln('les nombres impaires ',chi);
readln;readln;
end.
A voir également:
- Fonction str et val en pascal
- Fonction si et - Guide
- Turbo pascal - Télécharger - Édition & Programmation
- My pascal - Télécharger - Édition & Programmation
- Dev pascal - Télécharger - Édition & Programmation
- Fonction miroir - Guide
1 réponse
Tu ne peux pas écrire x:=val(ch[i]); la bonne syntaxe est en fait val(ch[i],x);
Après tu auras également une erreur avec le if, quand tu écris do en fait c'est un then qu'il faut...
Sinon ton programme marche...
Petite astuce au passage, pour tester si un nombre est impair il existe la fonction odd :
Après tu auras également une erreur avec le if, quand tu écris do en fait c'est un then qu'il faut...
Sinon ton programme marche...
Petite astuce au passage, pour tester si un nombre est impair il existe la fonction odd :
if odd(x) then chi:=chi+ch[i]+' ' else chp:=chp+ch[i]+' ';
program exe;
uses wincrt;
var ch,chi,chp:string; i,nb,x:integer;
begin
write(chr(7));{BIP!}
write(#7);{Re-BIP!}
write('donner un nombre entier svp :');
read(nb);
str (nb,ch);
chp:=''; chi:='';
for i:=1 to length(ch) do
begin
val(ch[i],nb,x);
if nb mod 2 = 0 then
chp:=chp+ch[i] else
chi:=chi+ch[i];
end;
writeln('les nombre paires ',chp);
writeln('les nombres impaires ',chi);
write(chr(7));{BIP!}
write(#7);{Re-BIP!}
write(chr(7));{BIP!}
write(#7);{Re-BIP!}
readln;readln;
end.