Contoh Source Code penggunaan Array dalam Pascal
USES CRT;
VAR
NAMA : ARRAY [1..5] OF STRING;
NILAI : ARRAY [1..5] OF INTEGER;
I : INTEGER;
INDEX : STRING;
TOTAL : INTEGER;
AVERAGE : REAL;
BEGIN
CLRSCR;
WRITELN('MEMASUKAN DATA ARRAY');
WRITELN('********************');
WRITELN;
FOR I :=1 TO 5 DO
BEGIN
WRITE('NAMA KE ',I,' :' ); READLN(NAMA[I]);
WRITE('NILAI KE ',I,' :' ); READLN(NILAI[I]);
END;
WRITELN;
WRITELN('MENAMPILAKAN DATA ARRAY');
WRITELN;
WRITELN(' NAMA NILAI INDEX ');
WRITELN('====================================');
FOR I :=1 TO 5 DO
BEGIN
IF NILAI[I]<=50 THEN INDEX:='E';
IF NILAI[I]>=60 THEN INDEX:='D';
IF NILAI[I]>=65 THEN INDEX:='C';
IF NILAI[I]>=70 THEN INDEX:='B';
IF NILAI[I]>=80 THEN INDEX:='A';
WRITELN(NAMA[I] :10, NILAI[I]:10, INDEX:10);
END;
WRITELN('====================================');
TOTAL :=0;
FOR I :=1 TO 5 DO
TOTAL :=TOTAL+NILAI[I];
WRITELN('TOTAL NILAI : ',TOTAL:10);
AVERAGE:=TOTAL DIV 5;
WRITELN('RATA - RATA : ',AVERAGE:10:1);
READLN;
END.
0 Comments