đây a ạ
const max=20;
type dathuc=record
bac:integer;
heso:array[1..max] of real;
end;
var A,B,C:dathuc;
i:integer;
procedure nhap(kh:string;var P:dathuc);
var Kt:char;
begin
with P do
begin
repeat
write('nhap bac cua da thuc ',kh,' : ',chr(ord(kh[1])+7),'= ');
readln(bac);
if bac>max then
writeln('bac cuada thuc phai <=', max);
until (bac>=1) and (bac<=max);
kt:=chr(ord(kh[1])-5);
for i:=bac downto 0 do
begin
write(kt,'[',i,']='); readln(heso);
end;
end;
end;
procedure indathuc(kyhieu:string; P:dathuc);
begin
write(kyhieu,'=');
with p do
begin
for i:=bac downto 1 do
begin
if heso<>0 then
begin
if frac(heso)=0 then
write(heso[1]:0:0,'.x')
else write(heso:0:2,'.x');
if i>1 then write('^',i);
end;
if heso[i-1]>0 then write('+');
end;
if heso[0]<>0 then
if frac(heso[0])=0 then write(heso[0]:0:0)
else write(heso[0]:0:2);
end;
writeln;
end;
procedure tong(P,Q:dathuc; var r:dathuc);
var i,j:integer;
begin
if p.bac>q.bac then R.bac:=P.bac
else R.bac:=q.bac;
for i:=r.bac downto 0 do
r.heso:=P.heso+q.heso;
writeln('tong cua hai da thuc f(x) va g(x) la:');
indathuc('S(x)=',R);
end;
procedure tong(P,Q:dathuc; var r:dathuc);
var i,j:integer;
begin
if p.bac>q.bac then R.bac:=P.bac
else R.bac:=q.bac;
for i:=r.bac downto 0 do
r.heso:=P.heso-q.heso;
writeln('tong cua hai da thuc f(x) va g(x) la:');
indathuc('H(x)=',R);
end;
procedure tich(p,Q:dathuc; var r;dathuc);
var i,j:integer;
begin
r.bac:=p.bac+q.bac;
for i:=0 to r.bac do r.heso:=0;
for i:=p.bac downto 0 do
or j:=q.bac downto 0 do
r.heso[i+j]:=R.heso[i+j]+p.heso*q.heso[j];
writeln('tich cua hai da thuc f(x) va g(x) la: ');
indathuc('p(x)=',R);
end;
procedure thuong(P,Q:dathuc; var R:dathuc);
var i,j,m,kk:integer;
du:dathuc;
begin
m:=p.bac-Q.bac;
if m<0 then
begin
writeln('khong chia duoc ');
readln;
exit;
end;
for i:=0 to m do r.heso:=0;
r.bac:=m;
for i:=m downto 0 do
begin
r.heso:=P.heso[p.bac]/Q.heso[Q.bac];
for j:=Q.bac downto 0 do
p.heso[p.bac-q.bac+j]:=p.heso[p.bac-q.bac+j]-r.heso*q.heso[j];
p.bac;=p.bac-1;
end;
du:=p;
while (du.heso[du.bac]=0) and (du.bac>0)
do du.bac:=du.bac-1;
write('thuong cua hai da thuc f(x) va g(x) la: ');
indathuc('T(x) ',R);
if (du.bac=0) and (du.heso[0]=0) then
writeln('day la phep chia het ')
else indathuc('da thuc du R(x) ',du);
end;
begin
nhap('f(x) ',A);
nhap('g(x) ',B);
writeln('cac da thuc vua nhap la: ');
indathuc('f(x) ',A);
indathuc('g(x) ',B);
tong(A,B,C);
hieu(a,b,c);
tich(a,b,c);
thuong(a,b,c);
readln;
readln;
end.