Contoh Program Pascal Array
Menentukan Bilangan Prima Dari Hasil Perkalian Dua Bilangan
Program Mencari_Bilangan_Prima_dari perkalian_dua_bilangan;
Uses winCrt;
Var
Prima : Array[1..100] of Integer;
i,j,a,b,c : Integer;
bil : Integer;
Begin
ClrScr;
write('Masukkan angka 1 = ');readln(a);
write('Masukkan angka 2 = ');readln(b);
c:=a*b;
writeln('Hasil= ',c);
For i := 2 to c Do
Begin
Prima[i]:=i;
For j:= 2 to i-1 Do
Begin
bil := (i mod j);
If bil = 0 then Prima[i]:=0;
End;
If Prima[i] <> 0 Then Write(Prima[i],' ');
End;
Readln;
end.
HASIL PROGRAM
Program Mencari_Bilangan_Prima_dari perkalian_dua_bilangan;
Uses winCrt;
Var
Prima : Array[1..100] of Integer;
i,j,a,b,c : Integer;
bil : Integer;
Begin
ClrScr;
write('Masukkan angka 1 = ');readln(a);
write('Masukkan angka 2 = ');readln(b);
c:=a*b;
writeln('Hasil= ',c);
For i := 2 to c Do
Begin
Prima[i]:=i;
For j:= 2 to i-1 Do
Begin
bil := (i mod j);
If bil = 0 then Prima[i]:=0;
End;
If Prima[i] <> 0 Then Write(Prima[i],' ');
End;
Readln;
end.
HASIL PROGRAM
Komentar
Posting Komentar