vendredi 29 mars 2024

PROGRAMME PASCAL

 

Quelques Corrections des Exercices : 

Exercice n° 03 :

program comparer_tableaux;
uses crt;
Var tab1,tab2:array[1..20] of integer;
i,n:integer;
identique:boolean;
begin
clrscr;
write('DONNER LA DIMENSION DES DEUX TABLEAUX: ');
read(n);
writeln('ENTRER LES ',n,' ELEMENTS DU 1ER TABLEAU: ');
For i:=1 to n do
begin
write('TAB1[',i,']= ');read(tab1[i]);
end;
writeln;
writeln('ENTRER LES ',n,' ELEMENTS DU 2EME TABLEAU: ');
For i:=1 to n do
begin
write('TAB2[',i,']= ');read(tab2[i]);
end;
identique := true;
for i := 1 to n do
begin
if tab1[i] <> tab2[i] then
begin
identique := false;
break;
end;
end;
if identique then
writeln('Les deux tableaux sont identiques.')
else
writeln('Les deux tableaux ne sont pas identiques.');
readkey;
END.
 

Exercice n° 04 :

Program rech_nombre;
uses crt;
var
T:array[1..50] of integer;
NombreRecherche: integer;
i,taille: integer;
trouve: boolean;
begin
Write('Donner la taille du tableau :');
Read(taille);
writeln('Entrez les ', TAILLE, ' élements du tableau :');
for i := 1 to taille do
readln(T[i]);
writeln('Entrez le nombre … rechercher dans le tableau :');
readln(nombreRecherche);
trouve := false;
for i := 1 to taille do
begin
if t[i] = NombreRecherche then
begin
trouve := true;
Break;
end;
end;
if trouve then
writeln('Le nombre ', nombreRecherche, ' existe dans le tableau.')
else
writeln('Le nombre ', nombreRecherche, ' n''existe pas dans le tableau.');
Readkey;
end.

Exercice n° 05 :

       
program NotesSuperieuresAMoyenne;
uses crt;
const
NB_NOTES = 10;
var
notes: array[1..NB_NOTES] of real;
somme, moyenne: real;
i, notesSupMoyenne: integer;
begin
clrscr;
writeln('Entrez les ',NB_NOTES,' notes :');
for i := 1 to NB_NOTES do
readln(notes[i]);
somme := 0;
for i := 1 to NB_NOTES do
somme := somme + notes[i];
moyenne := somme / NB_NOTES;
writeln('La moyenne des notes est : ', moyenne:0:2);
writeln('Les notes qui sont supérieurs à la moyenne sont : ');
notesSupMoyenne := 0;
for i := 1 to NB_NOTES do
begin
if notes[i] > moyenne then
begin
notesSupMoyenne := notesSupMoyenne + 1;
writeln(notes[i]:0:2);
end;
end;
writeln('Total des notes supérieures à la moyenne est : ', notesSupMoyenne);
Readkey;
end.
         

0 commentaires:

Enregistrer un commentaire