On écrit une procédure affichepoly qui permet d'afficher un polynôme P sous sa forme canonique :
On utilise le caractère circonflexe pour représenter les puissances et on doit respecter les contraintes suivantes :
Ainsi, le polynôme
ne devra pas s'afficher comme ceci :
+-1X^3 + 0X^2 + 4 X^1 +-1mais comme cela :
-X^3 + 4X -1La procédure s'écrit :
procedure affichepoly(P : polynome);
var i : integer;
polynomeNul : boolean;
begin
polynomeNul:=true;
for i:=P.degre downto 0 do
if (P.coef[i]<>0) then
begin
polynomeNul:=false;
if (P.coef[i]<0) then
write('-')
else if (i<P.degre) then
write('+');
if (abs(P.coef[i])<>1) or (i=0) then
write(abs(P.coef[i]):3:2);
if (i>0) then
write('X');
if (i>1) then
write('^',i:2);
end;
if polynomeNul then
write(0, '(polynome nul)');
end;