program ex3;
type
Tetat = (indetermine, indefinie, definie);
TFraction = record
Num: integer;
Deno: integer;
Etat: TEtat;
end;
var
i: integer;
f1, f2, f3: TFraction;
function pgcd (p, q: integer): integer;
var
aux: integer;
begin
if p < q then
begin
aux := p;
p := q;
q := aux;
end;
while q > 0 do
begin
aux := p mod q;
p := q;
q := aux;
end;
pgcd := p;
end; { Fin de
'pgcd' }
procedure InitFraction (var f: TFraction);
var
i: integer;
begin
repeat
writeln('Numerateur:');
readln(i);
until i<>0;
f.Num := i;
repeat
writeln('Denominateur:');
readln(i);
until i<>0;
f.Deno := i;
f.Etat := definie;
end; { Fin de
'InitFraction' }
procedure AfficherFraction (f: TFraction);
begin
if f.Etat = definie then
writeln(f.Num : 0, '/', f.Deno : 0)
else if f.Etat = indefinie then
writeln('indefinie')
else if f.Etat = indetermine then
writeln('indetermine')
end; { Fin de
'AfficherFraction' }
procedure ReductionFraction (var f: TFraction);
var
i: integer;
begin
i := pgcd(f.Num, f.Deno);
if i > 1 then
begin
f.Num := f.Num div i;
f.Deno := f.Deno div i;
end;
end; { Fin de
'ReductionFraction' }
procedure SommeFraction (f1, f2: TFraction; var res:
TFraction);
begin { f1/f2 }
res.Deno := f1.Deno * f2.Deno;
res.Num := f1.Deno * f2.Num + f2.Deno * f1.Num;
res.Etat := definie;
ReductionFraction(res);
end; { Fin de
'SommeFraction' }
procedure DivisionFraction (f1, f2: TFraction; var
res: TFraction);
begin
res.Num := f1.Num * f2.Deno;
res.Deno := f1.Deno * f2.Num;
res.Etat := definie;
ReductionFraction(res);
end; { Fin de
'DivisionFraction' }
begin { corps du
programme }
InitFraction(f1);
InitFraction(f2);
DivisionFraction(f1, f2, f3);
AfficherFraction(f3);
writeln('http://www.Software-DS.com');
{
http://www.Software-DS.com 13/11/01
}
end.
|