Membuat Kalkulator Lengkap Part2 Di delphi
Membuat kalkulator Lengkap Part2 Di delphi:
Program Kombinasi, permutasi dan Nilai Faktorial Di Delphi:
Untuk Permutasi Dan Kombinasi:
Untuk Permutasi:
procedure TForm1.Button1Click(Sender: TObject);
Function nPr(n,r:integer):real;
var
x:real;
i:integer;
begin
x:=1;
for i:=r+1 to n do x:=x*i;
nPr:=x;
End;
atau bisa juga
function PossiblePermutations(TargetLength: byte): extended;
function Factorial(I: WORD): extended;
begin
result := I;
while I > 1 do begin
Dec(I);
result := result *I;
end;
end;
var
z : integer;
n, nk : extended;
begin
{
n!
n_P_k = --------
(n - k)!
}
z := Length('abcdefghijklmnopqrstuvwxyz0123456789');
n := Factorial(z);
nk := Factorial(z -TargetLength);
result := n /nk;
end;
Untuk Kombinasi
procedure TForm1.Button1Click(Sender: TObject);
Function nCr(n,r:integer):real;
var
x,y:real;
i:integer;
begin
if r>n div 2 then r:=n-r;
x:=1; y:=1;
for i:=n-r+1 to n do x:=x*i;
for i:=2 to r do y:=y*i;
nCr:=x/y;
End;
atau bisa juga
procedure TForm1.Button1Click(Sender: TObject);
function nCr(n,r:word):anytype { range >= longint };
var
x:anytype;
i:word;
begin
if r>n then
nCr := 0
else begin
if r>n div 2 then r:=n-r;
x:=1;
for i:=1 to r do x:=x*(n-i+1) / {DIV for word and longint} i;
nCr:=x
end
End;
Untuk nilai Faktorial:
procedure TForm1.Button1Click(Sender: TObject);
var
x:real;
i,n:integer;
begin n:=strtoint(edit1.Text);
if n = 0 then
begin edit2.Text:=’1′;
label4.Caption:=edit1.Text + ‘ !';
end;
if n < 0 then begin
edit2.text:=’syntax error';
label4.Caption:=edit1.Text + ‘ !';
end;
if n > 0 then
begin
x:=1;
for i:=1 to n do
x:=x*i;
edit2.Text:=floattostr(x);
label4.Caption:=edit1.Text + ‘ !';
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Close;
end;
procedure.Form1.Button2Click(Sender: TObject);
begin
edit1.Text:=’ ‘;
edit2.Text:=’ ‘;
label4.Caption:=’ ‘;
end;
end.
Menghitung Nilai Integral Dengan Persamaan Di Delphi
Note: masih Terdapat Kekurangan Pada Menghitung Integral di delphi
procedure TForm1.Button1Click(Sender: TObject);
var
awal,akhir,delta,nilaiintegral,x,y,luasankecil,ylama:real;
i,j,jumlahlangkah:integer;
begin
for j:=1 to 10 do
begin
awal:=-10;
akhir:=10;
jumlahlangkah:=10*j;
delta:=(akhir-awal)/jumlahlangkah;
nilaiintegral:=0;
x:=awal;
ylama:=6*x*x+2*x+12;
for i:=1 to jumlahlangkah do
begin
x:=x+delta;
y:=6*x*x+2*x+12;
luasankecil:=ylama*delta+(delta/2)*y;
nilaiintegral:=nilaiintegral+abs(luasankecil);
ylama:=y;
end;
Memo1.Lines.Add(IntToStr(jumlahlangkah)+'nilai integralnya='+FloatToStr(nilaiintegral));
end;
end;
end.
Eksponensial (Exp) :
procedure TForm1.Button1Click(Sender: TObject);
var
float : Double;
begin
float := Ln(2);
ShowMessage('Ln(2) = '+FloatToStr(float));
float := Exp(float);
ShowMessage('Exp(Ln(2)) = '+FloatToStr
(float));
end;
Logarithm (Log) :
procedure TForm1.Button1Click(Sender: TObject);
var
float: double;
begin
ShowMessage('Log10(1) = '+FloatToStr
(Log10(1)));
ShowMessage('Log10(5) = '+FloatToStr
(Log10(5)));
ShowMessage('Log10(10) = '+FloatToStr
(Log10(10)));
end;
Program Kombinasi, permutasi dan Nilai Faktorial Di Delphi:
Untuk Permutasi Dan Kombinasi:
Untuk Permutasi:
procedure TForm1.Button1Click(Sender: TObject);
Function nPr(n,r:integer):real;
var
x:real;
i:integer;
begin
x:=1;
for i:=r+1 to n do x:=x*i;
nPr:=x;
End;
atau bisa juga
function PossiblePermutations(TargetLength: byte): extended;
function Factorial(I: WORD): extended;
begin
result := I;
while I > 1 do begin
Dec(I);
result := result *I;
end;
end;
var
z : integer;
n, nk : extended;
begin
{
n!
n_P_k = --------
(n - k)!
}
z := Length('abcdefghijklmnopqrstuvwxyz0123456789');
n := Factorial(z);
nk := Factorial(z -TargetLength);
result := n /nk;
end;
Untuk Kombinasi
procedure TForm1.Button1Click(Sender: TObject);
Function nCr(n,r:integer):real;
var
x,y:real;
i:integer;
begin
if r>n div 2 then r:=n-r;
x:=1; y:=1;
for i:=n-r+1 to n do x:=x*i;
for i:=2 to r do y:=y*i;
nCr:=x/y;
End;
atau bisa juga
procedure TForm1.Button1Click(Sender: TObject);
function nCr(n,r:word):anytype { range >= longint };
var
x:anytype;
i:word;
begin
if r>n then
nCr := 0
else begin
if r>n div 2 then r:=n-r;
x:=1;
for i:=1 to r do x:=x*(n-i+1) / {DIV for word and longint} i;
nCr:=x
end
End;
Untuk nilai Faktorial:
procedure TForm1.Button1Click(Sender: TObject);
var
x:real;
i,n:integer;
begin n:=strtoint(edit1.Text);
if n = 0 then
begin edit2.Text:=’1′;
label4.Caption:=edit1.Text + ‘ !';
end;
if n < 0 then begin
edit2.text:=’syntax error';
label4.Caption:=edit1.Text + ‘ !';
end;
if n > 0 then
begin
x:=1;
for i:=1 to n do
x:=x*i;
edit2.Text:=floattostr(x);
label4.Caption:=edit1.Text + ‘ !';
end;
end;
procedure TForm1.Button3Click(Sender: TObject);
begin
Close;
end;
procedure.Form1.Button2Click(Sender: TObject);
begin
edit1.Text:=’ ‘;
edit2.Text:=’ ‘;
label4.Caption:=’ ‘;
end;
end.
Menghitung Nilai Integral Dengan Persamaan Di Delphi
Note: masih Terdapat Kekurangan Pada Menghitung Integral di delphi
procedure TForm1.Button1Click(Sender: TObject);
var
awal,akhir,delta,nilaiintegral,x,y,luasankecil,ylama:real;
i,j,jumlahlangkah:integer;
begin
for j:=1 to 10 do
begin
awal:=-10;
akhir:=10;
jumlahlangkah:=10*j;
delta:=(akhir-awal)/jumlahlangkah;
nilaiintegral:=0;
x:=awal;
ylama:=6*x*x+2*x+12;
for i:=1 to jumlahlangkah do
begin
x:=x+delta;
y:=6*x*x+2*x+12;
luasankecil:=ylama*delta+(delta/2)*y;
nilaiintegral:=nilaiintegral+abs(luasankecil);
ylama:=y;
end;
Memo1.Lines.Add(IntToStr(jumlahlangkah)+'nilai integralnya='+FloatToStr(nilaiintegral));
end;
end;
end.
Eksponensial (Exp) :
procedure TForm1.Button1Click(Sender: TObject);
var
float : Double;
begin
float := Ln(2);
ShowMessage('Ln(2) = '+FloatToStr(float));
float := Exp(float);
ShowMessage('Exp(Ln(2)) = '+FloatToStr
(float));
end;
Logarithm (Log) :
procedure TForm1.Button1Click(Sender: TObject);
var
float: double;
begin
ShowMessage('Log10(1) = '+FloatToStr
(Log10(1)));
ShowMessage('Log10(5) = '+FloatToStr
(Log10(5)));
ShowMessage('Log10(10) = '+FloatToStr
(Log10(10)));
end;
Komentar
Posting Komentar