Professional Documents
Culture Documents
Bac Pratique 01062019 Algo Corrige4
Bac Pratique 01062019 Algo Corrige4
Bac Pratique 01062019 Algo Corrige4
pas
Program CalcPPCM;
Uses WinCrt;
Type
tab=Array[1..100] of Integer;
enreg=Record
a,b:Integer;
ppcm:LongInt;
end;
fiche=file of enreg;
Var
n:Integer;
fe:fiche;
Function Puissance(x,y:Integer):LongInt;
Var
p:LongInt;
i:Integer;
Begin
p:=1;
for i:=1 To y Do
p:=p*x;
Puissance:=p;
end;
Function calcul_ppcm(a,b:Integer):Integer;
Var
TA,TB,DA,DB:tab;
i,m,p,nb_a,nb_b:Integer;
resultat:longint;
Begin
Facteurs_premiers(a,TA,m);
Facteurs_premiers(b,TB,p);
Distincts_elts(TA,m,DA,nb_a);
Distincts_elts(TB,p,DB,nb_b);
resultat:=1;
calcul_ppcm:=resultat;
End;
Repeat
write('Donner a n°',i,':=');Readln(a);
Until (a>0) and (a<=1000);
e.a:=a;
Repeat
write('Donner b n°',i,':=');Readln(b);
Until (b>0) and (b<=1000);
e.b:=b;
e.ppcm:=calcul_ppcm(a,b);
Write(fe,e);
End;
close(fe);
Begin
saisie(n);
Assign(fe,'c:\F_PPCM.dat');
remplissage(n,fe);
affichage(fe);
End.