Une solution de l'exercice 2 du TP6 d'informatique en DEUG MIAS+MASS S1
PROGRAM tp6exc2 ;
CONST nmax = 100 ;
VAR n,i,temp : integer ;
T : array[1..nmax] of integer ;
choix : char ;
BEGIN
randomize ;
(* saisie de N *)
repeat
write('Combien d''entiers (1 à ',nmax,') ? ') ;
readln(n) ;
until (n>0) and (n<nmax) ;
(* remplissage du tableau et affichage *)
for i:=1 to n do
begin
T[i]:=random(14)+2 ;
write(T[i]:3) ;
end ;
writeln ;
(* menu et choix *)
writeln ;
writeln('-1- permutation circulaire des éléments du tableau') ;
writeln('-2- inversion de la partie remplie du tableau') ;
repeat
write('votre choix ? ') ;
readln(choix) ;
until (choix='1') or (choix='2') ;
writeln ;
(* realisation du choix *)
if choix='1'
then begin (* permutation *)
temp:=T[n] ;
for i:=n downto 2 do
T[i]:=T[i-1] ;
T[1]:=temp ;
writeln('après permutation circulaire : ') ;
end
else begin (* inversion *)
for i:=1 to (n div 2) do
begin
temp:=T[i] ;
T[i]:=T[n+1-i] ;
T[n+1-i]:=temp ;
end ;
writeln('après inversion : ') ;
end ;
(* affichage du résultat *)
for i:=1 to n do write(T[i]:3) ;
writeln ;
END.