program wielomian;
uses crt;
var A: array[0..10] of integer;
    n,i: byte;
    klawisz: char;
    x,y: real;
label poczatek;

function pot(x,y:real):real;
  begin
  if x=0 then pot:=0;
  if x>0 then pot:=exp(y*ln(x));
  if x<0 then begin
            if (trunc(abs(y)) mod 2 = 0) then
            pot:=exp(y*ln(abs(x)));
            if (trunc(abs(y)) mod 2 = 1) then
            pot:=-exp(y*ln(abs(x)));
            end;
  end;

begin
poczatek:
clrscr;
textcolor(11);
writeln;
writeln('               Program oblicza wartosc wielomianu dla podanego');
writeln('                                argumentu');
write('Podaj stopien wielomianu, (-1<n<11) n = '); readln(n);
for i:=n downto 0 do
begin
     write('a',i,' = ');
     readln(A[i]);
end;
write('Podaj wartosc argumentu: x = ');
readln(x);
y:=0;

for i:=0 to n do
y:=y+A[i]*x;

writeln('Wielomian wyglada nastepujaco:');
write('W(x) = ');textcolor(15);write(A[n]);textcolor(11);write('x^',n);
if n>0 then
for i:=n-1 downto 0 do
begin
     if A[i]>0 then begin
     write(' + ');textcolor(15);write(A[i]);textcolor(11);write('x^',i);
     end;
     if A[i]<0 then begin
     write(' - ');textcolor(15);write(abs(A[i]));textcolor(11);write('x^',i);
     end;
end;
writeln;
writeln('Dla podanego argumentu:');
write('W(x) = ');textcolor(15);write(A[n]);textcolor(11);write('*',x:2:2,'^',n);
if n>0 then
for i:=n-1 downto 0 do
begin
     if A[i]>0 then begin
     write(' + ');textcolor(15);write(A[i]);textcolor(11);write('*',x:2:1,'^',i);
     end;
     if A[i]<0 then begin
     write(' - ');textcolor(15);write(abs(A[i]));textcolor(11);write('*(',x:2:1,')^',i);
     end;
end;
writeln;
writeln('Wartosc wielomianu dla podanego argumentu, y = ',y:2:5);

textcolor(11);
writeln;writeln;writeln;
write('Czy powtorzyc obliczenia? (t/n)');
klawisz:=readkey;
if klawisz='t' then goto poczatek;
end.
