Fonction str et val en pascal
Fermé
oh9007
Messages postés
41
Date d'inscription
mardi 10 février 2009
Statut
Membre
Dernière intervention
15 septembre 2010
-
16 févr. 2009 à 08:21
oh9007 - 25 févr. 2009 à 21:01
oh9007 - 25 févr. 2009 à 21:01
A voir également:
- Fonction str et val en pascal
- Turbo pascal download - Télécharger - Édition & Programmation
- Fonction si et - Guide
- My pascal - Télécharger - Édition & Programmation
- Fonction si avec date ✓ - Forum Excel
- Mise en forme conditionnelle en fonction d'une autre cellule ✓ - Forum Excel
1 réponse
KX
Messages postés
16668
Date d'inscription
samedi 31 mai 2008
Statut
Modérateur
Dernière intervention
17 mars 2023
3 005
24 févr. 2009 à 16:06
24 févr. 2009 à 16:06
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]+' ';
25 févr. 2009 à 21:01
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.