Selasa, 31 Maret 2015

PROGRAM SORTING DENGAN MENGGUNAKAN BAHASA PASCAL (Descending)


Source Code
uses crt;

type data= record
nama, nim: string;
ipk : real;
end;

var
mhs : array [1..10] of data;
i, j, n, temp : integer;
pilih : char;

procedure input;
begin
clrscr;
write('Masukkan Jumlah Mahasiswa : '); readln(n);
for i := 1 to n do

begin
clrscr;
writeln('Masukkan Data ke- ', i);
writeln('=====================');
write ('Nama  : '); readln(mhs[i].nama);
write ('NIM   : '); readln(mhs[i].nim);
write ('IPK   : '); readln(mhs[i].ipk);
end;
end;

procedure hasil;
begin
clrscr;
writeln('=========');
writeln('= HASIL =');
writeln('=========');
for i:=1 to n do

begin
writeln;
writeln('Hasil Data Ke-',i);
writeln('NIM  : ',mhs[i].nim);
writeln('NAMA : ',mhs[i].nama);
writeln('IPK  : ',mhs[i].ipk:2:2);
end;

readkey;
end;

procedure seleksi;
var max: integer;
temp: data;

begin
for i:=1 to n-1 do

begin
max:=i;
for j:= i+1 to n do
if mhs[j].ipk> mhs[max].ipk then

max:=j;

temp:= mhs[max];
mhs[max]:= mhs[i];
mhs[i]:= temp;
end;
hasil;
end;

begin
input;
seleksi;
end.

 


Tidak ada komentar:

Posting Komentar