Array dalam C++
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
char nama[20][10];
char npm[8][10];
char kelas[5][10];
int jml;
cout<<"Masukkan jumlah record:";
cin>>jml;
clrscr();
for(int i=0;i<=jml;i++)
{
cout<<"\n input data ke-"<< i <<":";
cout<<"\n nama ke-"<<i<<":";
cin>>nama[i];
cout<<"\n npm ke-"<<i<<":";
cin>>npm[i];
cout<<"\n kelas ke-"<<i<<":";
cin>>kelas[i];
}
for(int j=0;j<=jml;j++)
{
cout<<"\n input data ke-"<< j;
cout<<"\n nama : "<< nama [j];
cout<<"\n npm : "<< npm [j];
cout<<"\n kelas : "<< kelas [j];
cout<<"\n================================\n";
}
getch();
}
Array dalam bahasa Cobol
DENTIFICATION DIVISION.
PROGRAM-ID. MATRIK.
AUTHOR. NURFITRIANA.
ENVIRONMENT DIVISION.
DATA DIVISION.
WORKING-STORAGE SECTION.
77 I PIC 99.
77 J PIC 99.
01 MASUKAN.
02 MATRIK OCCURS 2 TIMES.
03 MAT1 OCCURS 2 TIMES PIC 9.
03 MAT2 OCCURS 2 TIMES PIC 9.
03 MAT-HASIL OCCURS 2 TIMES PIC ZZZ.
SCREEN SECTION.
01 HAPUS-LAYAR.
02 BLANK SCREEN.
PROCEDURE DIVISION.
MULAI.
DISPLAY HAPUS-LAYAR.
MOVE 2 TO LIN.
DISPLAY(LIN, 1) 'MATRIK PERTAMA'.
ADD 1 TO LIN.
PERFORM MATRIK1 VARYING I
FROM 1 BY I UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2.
MOVE 1 TO LIN.
DISPLAY(LIN, 30) 'MATRIK KEDUA'.
ADD 1 TO LIN.
PERFORM MATRIK2 VARYING I
FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2.
MOVE 1 TO LIN.
DISPLAY (10, 10) 'PENJUMLAHAN MATRIK'.
DISPLAY SPACE.
MOVE 13 TO COL.
PERFORM HITUNG-NILAI VARYING I
FROM 1 BY 1 UNTIL I > 1
AFTER J FROM 1 BY 1 UNTIL J > 1.
MOVE 13 TO COL.
PERFORM HITUNG-NILAI VARYING I
FROM 1 BY 1 UNTIL I > 2
AFTER J FROM 1 BY 1 UNTIL J > 2.
STOP RUN.
MATRIK1.
DISPLAY(LIN, 1) 'NILAI[', I , ',' , J , ']:'.
ACCEPT ( , ) MAT1(I, J).
ADD 1 TO LIN.
MATRIK2.
DISPLAY(LIN, 30) 'NILAI[', I , ',' , J , ']:'.
ACCEPT ( , ) MAT2(I, J).
ADD 1 TO LIN.
HITUNG-NILAI.
COMPUTE MAT-HASIL(I, J) = MAT1(I, J) + MAT2(I, J).
DISPLAY ( , COL) MAT-HASIL(I, J).
ADD 7 TO COL.
Array pada bahasa Pascal
USES WINCRT;
VAR
I :LONGINT;
NM :ARRAY[1..100]OF STRING[25];
HK,SUBT :ARRAY[1..100]OF REAL;
LM :ARRAY[1..100]OF INTEGER;
TOT :REAL;
BEGIN
I:=1;
WHILE(I<=3) DO
BEGIN
WRITELN('DATA KE :',I);
WRITELN('===========');
WRITE('INPUTKAN NAMA TAMU :');READLN(NM[I]);
WRITE('INPUTKAN LAMA MENGINAP :');READLN(LM[I]);
WRITE('INPUTKAN HARGA KAMAR :');READLN(HK[I]);
SUBT[I] :=LM[I] * HK[I];
WRITELN;
TOT :=TOT + SUBT[I];
I:=I +1;
END;
WRITELN('--------------------------------------------------');
WRITELN('NO NAMA LAMA HARGA SUB ');
WRITELN(' TAMU MENGINAP KAMAR TOTAL ');
WRITELN('--------------------------------------------------');
FOR I:=1 TO 3 DO
BEGIN
WRITELN(I:3,NM[I]:15,LM[I]:10,HK[I]:10:0,SUBT[I]:8:0);
END;
WRITELN('--------------------------------------------------');
WRITELN('TOTAL :',TOT:12:0);
END.
Array dalam bahasa Ruby
nama=[]
kelas=[]
uts=[]
uas=[]
print "Jumlah data : "
data=gets.to_i
for i in 1.. data
print "\nMasukan Nama :"
nama=gets.to_s
print "Masukan Kelas : "
kelas=gets.to_s
print "Masukan Nilai Uts : "
uts=gets.to_i
print "Masukan Nilai Uas : "
uas=gets.to_i
end
print "\n======================\n"
print "Data Yang Anda Masukan"
print "\n======================\n"
for i in 1 .. data
print "\nNama Ke- ",i,": ",nama
print "Kelas Ke- ",i,": ",kelas
print "Nilai Uts ",i,": ",uts,"\n"
print "Nilai Uas ",i,": ",uas,"\n"
x=(uts+uas)
print "Nilai Total ",i,": ",x,"\n"
end
0 Comment "Contoh Program Array dalam beberapa bahsa"
Post a Comment