Arsip: nilai minimum, maximum array dan matrix
more 16 years ago
yadi
bro,,,,,n rekan2,,,
gimana ya buat cari nilai minimum dan maximum array dinamis dan matrix dinamis,,
misal
baris : array of real = (0,1,2,3,4,5,6,7,8,9,10);
min = 0;
max= 10;
matrix : array of real =
((0,1,2,3),
(255,3,4,5),
(50,8,2,1),
(4,3,2,1));
min = 0;
max = 255;
thank's ya ...wat semuanya... :D
more 16 years ago
pebbie
type
TRealArray = array of real;
TRealMatrix = array of array of real;
function min2(a,b:real):real;begin
if a<b then result := a else result := b;
end;
function max2(a,b:real):real;begin
if a>b then result := a else result := b;
end;
var
j, i : integer;
arrmin, arrmax : real;
matmin, matmaks : real;
baris : TRealArray;
matrix : TRealMatrix;
begin
arrmin := MAXINT;
arrmax := -arrmin;
for j := low(baris) to high(baris) do begin
arrmin := min2(arrmin, baris[j]);
arrmax := max2(arrmax, baris[j]);
end;
matmin := MAXINT;
matmaks := -matmin;
for j := low(matrix) to high(matrix) do begin
for i := low(matrix[j]) to high(matrix[j]) do begin
matmin := min2(matrix[j][i], matmin);
matmaks := max2(matrix[j][i], matmaks);
end;
end;
end;
more 16 years ago
yadi
Thank's mas @pebbie,,,
ta cobain dulu ya,,,,,
tanya lagi ya kalo ada kesulitan... :D
more 16 years ago
yadi
thank's ya,,,sempet ga tau juga he..he,,,
cara gunakan fungsinya...
tapi dah bisa n mudah2an tepat exactly... ta modif
kalo ga tepat.rekan2 semuanya kasih tau..ya...
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
PArray = Array of real;
PMatrik = array of real;
TRealArray = array of real;
TRealMatrix = array of array of real;
type
TForm1 = class(TForm)
Button1: TButton;
Edit1: TEdit;
Edit2: TEdit;
Button2: TButton;
Edit3: TEdit;
Edit4: TEdit;
Edit5: TEdit;
Edit6: TEdit;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Label4: TLabel;
Label5: TLabel;
Label6: TLabel;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
barisarray : PArray =
(-1,2,3,4,5,6,7,8,9,10,11);
matriksku : PMatrik =
((1,2,3,4),
(255,3,4,1),
(3,2,1,4),
(4,3,2,0));
implementation
{$R .dfm}
function Rata2baris(x : PArray):real;
var
i,jumlah,panjang : integer;
hasil : real;
begin
jumlah := 0 ;
for i := 0 to length(x) - 1 do
begin
jumlah := jumlah + round(x[i]);
End;
panjang := length(x);
hasil := jumlah/panjang;
Rata2baris := hasil;
end;
function Rata2matrix(x1: PMatrik): real ;
var
i,j,jumlah,nilai : integer;
hasil : real;
begin
jumlah := 0 ;
for i := 0 to length(x1) - 1 do
begin
for j:= 0 to length(x1[0])-1 do
begin
jumlah := jumlah + round(x1[i,j]);
End;
End;
nilai := length(x1) length(x1[0]);
hasil := jumlah/nilai;
Rata2matrix := hasil;
End;
function min2(a,b:real):real;
begin
if a<b then
result := a
else
result := b;
end;
function max2(a,b:real):real;
begin if a>b then
result := a
else
result := b;
end;
function nilaimax( matrix : PMatrik):Real;
var
j, i : integer;
matmin, matmaks : real;
begin
matmin := MAXINT;
matmaks := -matmin;
for j := low(matrix) to high(matrix) do
begin
for i := low(matrix[j]) to high(matrix[j]) do
begin
matmaks := max2(matrix[j][i], matmaks);
end;
result := matmaks;
end;
end;
function nilaimin( matrix : PMatrik):Real;
var
j, i : integer;
matmin : real;
begin
matmin := MAXINT;
// matmaks := -matmin;
for j := low(matrix) to high(matrix) do
begin
for i := low(matrix[j]) to high(matrix[j]) do
begin
matmin := min2(matrix[j][i], matmin);
end;
result := matmin;
end;
end;
function nilaiminbaris( baris : PArray):Real;
var
j : integer;
arrmin : real;
begin
arrmin := MAXINT;
// arrmax := -arrmin;
for j := low(baris) to high(baris) do
begin
arrmin := min2(arrmin, baris[j]);
end;
result := arrmin;
end;
function nilaimaxbaris( baris : PArray):Real;
var
j : integer;
arrmin, arrmax : real;
begin
arrmin := MAXINT;
arrmax := -arrmin;
for j := low(baris) to high(baris) do
begin
arrmax := max2(arrmax, baris[j]);
end;
result := arrmax;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
nilairata2 : real;
nilairata2gambar : real;
begin
nilairata2 := Rata2baris(barisarray);
edit1.Text := FloatToStr(nilairata2);
nilairata2gambar := Rata2matrix(matriksku);
edit2.Text := Floattostr(nilairata2gambar);
end;
procedure TForm1.Button2Click(Sender: TObject);
var
Minbaris, MaxBaris : Real;
MinMatrix, MaxMatrix : Real;
begin
MaxBaris := nilaimaxbaris(barisarray);
edit3.Text := FloatToStr(MaxBaris);
Minbaris := nilaiminbaris(barisarray);
edit4.Text := FloatTostr(MinBaris);
MaxMatrix := NilaiMax(matriksku);
edit5.Text := FloatToStr(MaxMatrix);
MinMatrix := NilaiMin(matriksku);
Edit6.Text := FloatToStr(MinMatrix);
end;
end;
:D
more ...
- Pages:
- 1
reply |
Report Obsolete
Last Articles
Last Topic
- PascalTalk #6: (Podcast) Kuliah IT di luar negeri, susah gak sih?
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #5: UX: Research, Design and Engineer
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #4: Obrolan Ringan Seputar IT
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #2: Membuat Sendiri SMART HOME
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #3: RADically Fast and Easy Mobile Apps Development with Delphi
by LuriDarmawan in Tutorial & Community Project more 4 years ago - PascalTalk #1: Pemanfaatan Artificial Intelligence di Masa Covid-19
by LuriDarmawan in Tutorial & Community Project more 4 years ago - Tempat Latihan Posting
by LuriDarmawan in OOT more 4 years ago - Archive
- Looping lagi...
by idhiel in Hal umum tentang Pascal Indonesia more 12 years ago - [ask] koneksi ke ODBC user Dsn saat runtime dengan ado
by halimanh in FireBird more 12 years ago - Validasi menggunakan data tanggal
by mas_kofa in Hal umum tentang Pascal Indonesia more 12 years ago
Random Topic
- cetak ke printer secara manual
by jkssbma in Enginering more 18 years ago - Penjadwalan dengan Metode Algoritma genetika use delphi
by goin in Tip n Trik Pemrograman more 15 years ago - [?] Bikin Pack atau Update-an u/ Program yg Sudah Berjalan?
by babypigs in Enginering more 17 years ago - Bagaimana buat Database local
by oloan_ac in Hal umum tentang Pascal Indonesia more 17 years ago - membuat nomor urut di query ms access
by jajang in Hal umum tentang Pascal Indonesia more 13 years ago - Parameter utk report
by l1th1um in Reporting more 17 years ago - tanya date
by brodien in Tip n Trik Pemrograman more 18 years ago - Perkalaian antara 2 buah listbox
by mysweetaurel in Hal umum tentang Pascal Indonesia more 16 years ago - Mohon bantuan...grayscale dan resize
by delphier in Multimedia & Graphic Enhancement more 16 years ago - Meng-Copy Isi Tabel Ke Tabel Lainnya
by doodle_doo in MsSQL more 16 years ago