program Horner;
uses wincrt;
var
h, i, j, cek, n, p : integer;
z : real;
e, k, l : array [1..100] of real;
label 1, 2;
begin
write('Masukkan pangkat tertinggi(maksimal pangkat 100): ');readln(n);
writeln('Apakah anda ingin menampilkan pengerjaan horner?');
writeln('Masukkan koefisien dan konstanta');
for i:= 1 to n+1 do
begin
write('k',i,' = ');readln(k[i]);
end;
if p = 1 then clrscr;
for i:= 1 to n+1 do
begin
e[i]:= k[i];
if p = 1 then write(' ',k[i]:0:6);
end;
writeln;
for cek:= 1 to n+1 do
begin
for i:= -100 to 100 do
begin
for j:= -100 to 100 do
begin
if j <> 0 then
begin
z:= e[1];
for h:= 2 to 5-cek do
begin
z:= e[h] + z*(i/j);
end;
if z = 0 then
begin
z:= e[1];
write(' ');
for h:= 2 to 5-cek do
begin
if p = 1 then write(' ',z*(i/j):0:6);
z:= e[h] + z*(i/j);
e[h]:= z;
end;
if p = 1 then
begin
writeln;
writeln('---------------------------------------------------+');
for h:= 1 to 5-cek do
begin
write(' ',e[h]:0:6);
end;
writeln;
end;
l[cek]:= i/j;
goto 1;
end;
end;
end;
end;
1:
end;
2:
writeln;
for i:= 1 to n do
begin
writeln('akar ',i,' = ',l[i]:0:10);
end;
end.
Preview Program:
Jika dipilih 1 (Ya), maka hasilnya akan seperti gambar dibawah ini.
Jika dipilih 2 (Tidak), maka hasilnya akan seperti gambar dibawah ini.
Tidak ada komentar:
Posting Komentar