Program Max1_Max2;
Uses Wincrt;
Var
x: array[1..100] of integer;
i,n,max,sec: integer;
Begin
Write('Masukkan Jumlah Data: ');readln(n);
for i := 1 to n do
begin
x[i]:=random(18);
write(x[i],' ');
{readln(x[i]);}
end;
max:=x[1];
sec:=0;
for i := 1 to n do
begin
if (x[i]>max) then
begin
if (sec<max) then
sec:=max;
max:=x[i];
end;
if (max>x[i]) and (sec<x[i]) then sec:=x[i];
end;
writeln;
writeln('Max= ',max);
Komunitas eLearning IlmuKomputer.Com
Copyright © 2003-2008 IlmuKomputer.Com
25
writeln('Second= ',sec);
End.
Program Pisahkan_Rekursif;
Uses Wincrt;
Procedure pisah(x,y:integer);
Begin
Writeln(x,'<--->',y);
if x<y then
begin
pisah(x,(x+y) div 2);
pisah((x+y) div 2+1,y);
end;
End;
Begin
pisah(5,10);
End.
Program Polinomial;
Uses Wincrt;
Type Larik = Array [1..10] of Integer;
var P1,P2,HP: Larik;
i,n,m,o: Integer;
Procedure Input(q:integer; var P:Larik);
Begin
for i := q+1 downto 1 do
begin
Write('nilai dari pangkat ke-',i-1,': ');Readln(P[i]);
end;
End;
Procedure Tampil(q:integer; P:Larik);
Begin
for i := q+1 downto 1 do
begin
if P[i]<>0 then
if i=q+1 then
Write(P[i],'x^',i-1)
else if P[i]>0 then
begin
if i=1 then
Write('+',P[i])
else if i=2 then
Write('+',P[i],'x')
else
Write('+',P[i],'x^',i-1);
end
else
begin
if i=1 then
Write(P[i])
else if i=2 then
Write(P[i],'x')
else
Write(P[i],'x^',i-1);
end;
end;
End;
Begin
Clrscr;
Writeln('Program Penjumlahan 2 Polinomial');
Writeln('================================');
Write('Masukkan Jumlah Pangkat Tertinggi Polinomial Ke-1:
');Readln(n);
Input(n,P1);
Write('P1 = ');
Tampil(n,P1);
Writeln;Writeln;
Write('Masukkan Jumlah Pangkat Tertinggi Polinomial Ke-2:
');Readln(m);
Input(m,P2);
Write('P2 = ');
Tampil(m,P2);
if m>n then
o:=m
else
o:=n;
Writeln;
Write('Hasil Polinomial (P1+P2): ');
for i := o+1 downto 1 do
HP[i]:=P1[i]+P2[i];
Tampil(o,HP);
End.
Program Menyusun_Rentang_Nilai;
Uses Wincrt;
Var i,tot,n:integer;
Begin
Write('Masukkan Jumlah Rentang Nilai: ');Readln(n);
For i:= 1 to n do
Begin
if (i mod 3 = 0) then
Begin
tot:=tot-i;
write('-',i);
End
else
Begin
tot:=tot+i;
if (i=1) then
write(i)
else
write('+',i);
End;
End;
Writeln;
Writeln('Total Rentang Nilai: ',tot);
End.
0 komentar:
Posting Komentar