1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
program test;
type
complexe=record
re,im:real;
end;
pcomplexe=^complexe;
procedure affichage(c:pcomplexe);
begin
with c^ do
if im<0 then
writeln(re:3:2,im:3:2,'i')
else
writeln(re:2:3,'+',im:2:3,'i');
end;
{METHODE 1}
function ajout1(c1,c2:pcomplexe):pcomplexe;
begin
ajout1^.re:=c1^.re+c2^.re;
ajout1^.im:=c1^.im+c2^.im;
end;
{METHODE 2}
function ajout2(c1,c2:pcomplexe):pcomplexe;
var
temp:pcomplexe;
begin
new(temp);
temp^.re:=c1^.re+c2^.re;
temp^.im:=c1^.im+c2^.im;
ajout2:=temp;
end;
{METHODE 2 avec dispose (normalement marche pas)}
function ajout3(c1,c2:pcomplexe):pcomplexe;
var
temp:pcomplexe;
begin
new(temp);
temp^.re:=c1^.re+c2^.re;
temp^.im:=c1^.im+c2^.im;
ajout3:=temp;
dispose(temp);
end;
var
a,b:pcomplexe;
begin
new(a);
new(b);
a^.re:=1;a^.im:=1;
b^.re:=1;b^.im:=1;
{affichage(ajout1(a,b));
affichage(ajout2(a,b));}
affichage(ajout3(a,b));
dispose(a);
dispose(b);
end. |
Partager