Académique Documents
Professionnel Documents
Culture Documents
1) Saisir une chaîne de caractère non vide et de longueur maximale égale à 10.
Program Saisir_Chaine;
Var
chaine: string[10];
begin
WriteLn('Saisir une chaîne de caractère non vide:');
ReadLn(chaine);
WriteLn('Votre chaîne est : ', chaine);
end.
Program Chaine_Alphabetique;
Var chaine: string;
i: integer;
test: boolean;
Begin
WriteLn('Saisir une chaîne de caractères :');
ReadLn(chaine);
i := 1;
test := true;
While (chaine[i] <> #0) do
Begin
If NOT ((chaine[i] >= 'a') and (chaine[i] <= 'z') or (chaine[i] >= 'A') and (chaine[i] <= 'Z'))
Then test := false;
i := i+ 1;
End;
If(test) then
WriteLn('La chaîne est alphabétique.')
Else
WriteLn('La chaîne n est pas alphabétique.')
End.
Program Verifier_Caractere;
Var
chaine: string;
c: char;
cpt, i: integer;
Begin
WriteLn('Saisir une chaîne de caractères :');
ReadLn(chaine);
WriteLn('Saisir le caractère à rechercher :');
ReadLn(c);
cpt:= 0;
i:= 0;
Repeat
i := i+1;
if (chaine[i] = c) then
cpt := cpt + 1
Until(chaine[i] = #0);
WriteLn('Le caractère ', c, ' apparaît ', cpt, ' fois dans la chaîne ', chaine,’.’);
End.
Program Nombre_Voyelles;
Var mot : string;
i, cpt: integer;
Begin
WriteLn('Saisir une chaîne de caractères :');
ReadLn(mot);
cpt :=0;
i:=1;
While(mot[i] <> #0) do
begin
if(mot[i] in [ 'A' , 'a' , 'E' , 'e' , 'I' , 'i' , 'O' , 'o' , 'U' , 'u' , 'Y' , 'y' ]) then
cpt := cpt + 1;
i := i+1;
End;
if(cpt>0) then
WriteLn('le mot << ', mot ,' >> contient ', cpt,' des voyelles')
Else
WriteLn('le mot << ', mot ,' >> ne contient pas des voyelles')
End.
1 2 3
ABC DEF
4 5 6
GHI JKL MNO
7 8 9
PQRS TUV WXYZ
* 0 #
+ -
Program Message_Chiffre;
Var mot, mot_chiffre : string;
i : integer;
Function Lettre_C(c : char): string;
Begin
Case c Of
'A', 'a': Lettre_C:='2'; 'B', 'b': Lettre_C:='22'; 'C', 'c': Lettre_C:='222';
'D', 'd': Lettre_C:='3'; 'E', 'e': Lettre_C:='33'; 'F', 'f': Lettre_C:='333';
'G', 'g': Lettre_C:='4'; 'H', 'h': Lettre_C:='44'; 'I', 'i': Lettre_C:='444';
'J', 'j': Lettre_C:='5'; 'K', 'k': Lettre_C:='55'; 'L', 'l': Lettre_C:='555';
'M', 'm': Lettre_C:='6'; 'N', 'n': Lettre_C:='66'; 'O', 'o': Lettre_C:='666';
'P', 'p': Lettre_C:='7'; 'Q', 'q': Lettre_C:='77';
'R', 'r': Lettre_C:='777'; 'S', 's': Lettre_C:='7777';
'T', 't': Lettre_C:='8'; 'U', 'u': Lettre_C:='88'; 'V', 'v': Lettre_C:='888';
'W', 'w': Lettre_C:='9'; 'X', 'x': Lettre_C:='99';
'Y', 'y': Lettre_C:='999'; 'Z', 'z': Lettre_C:='9999';
End;
End;
Begin
WriteLn('Saisir un mot');
ReadLn(mot);
i:=1;
mot_chiffre:='';
While(mot[i] <> #0) do
Begin
mot_chiffre := mot_chiffre + Lettre_C(mot[i]) ;
i := i+1;
Bnd;
WriteLn('le mot << ', mot ,' >> en chiffres c est << ', mot_chiffre,' >>');
End.
7)Programme qui permet de dire si deux mots sont anagrammes ou non. Ça veut
dire si elles sont formées par les mêmes caractères. Ex: Chien et Chine sont des anagrammes.
Program Message_Chiffre;
Var ch1,ch2 : string;
i,j : integer;
test : boolean;
Function Test_Caractere (c: char; mot: string): boolean;
Var cpt: integer;
testC : boolean;
Begin
cpt:=1;
testC := false;
While(mot[cpt] <> #0) do
Begin
if(mot[cpt] = c) then testC := true;
cpt := cpt+1;
End;
Test_Caractere:= testC;
End;
Begin
WriteLn('Saisir un le premier mot :');
ReadLn(ch1);
WriteLn('Saisir un le deuxieme mot :');
ReadLn(ch2);
i:=1;
test:=true;
While(ch1[i] <> #0) do
Begin
If (Test_Caractere(ch1[i],ch2) = false) Then test := false;
i := i+1;
End;
If(test = true) Then
WriteLn('le mot << ', ch1 ,' >> et << ',ch2,' >> sont des anagrammes')
Else
WriteLn('le mot << ', ch1 ,' >> et << ',ch2,' >> ne sont pas des anagrammes')
End.