Laman

Tampilkan postingan dengan label Pascal. Tampilkan semua postingan
Tampilkan postingan dengan label Pascal. Tampilkan semua postingan

Kamis, 02 Mei 2013

Contoh Program Daftar Mahasiswa pada Pascal



PROGRAM Daftar_Mahasiswa;
Uses crt;
Const jml = 50;
Type nm = array[1..50] of string;
npm = array[1..50] of  char;
jk = array[1..50] of string;
var nama: nm;
      nomor: npm;
      jenis: jk;
     a: byte;
begin
writeln(‘Memasukkan data-data mahasiswa’);
for a := 1 to jml do
begin
clrscr;
write(‘nama mahasiswa = ‘);readln(nama [a]);
write(‘npm mahasiswa = ‘);readln(nomor [a]);
write(‘jenis kelamin mahasiswa = ‘);readln(jenis [a]);
end;
{Mencetak Nama, NPM, dan Jenis Kelamin Mahasiswa}
Clrscr;
Writeln(‘-----------------------------------------------------------------------------------------------‘);
Writeln(‘|No.|                 Nama                        |           NPM           |               JK                |’);
Writeln(‘-----------------------------------------------------------------------------------------------‘);
For a := 1 to jml do
begin
write(a);
write(nama [a]);
write(nomor [a]);
writeln(jenis [a]);
end;
writeln(‘------------------------------------------------------------------------------------------------‘);
readln;
end.

Selasa, 22 Mei 2012

Contoh Program Paskal Pengaplikasian Looping If menggunakan For do

uses crt;
var a,b : integer;
begin
clrscr;
for a:= 1 to 6 do
begin
if a=6 then write(a,'=') else write(a,'+');
end; write((a+1)*3); readln; end.


Hasil:

1+2+3+4+5+6=21



Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2

Contoh Program Paskal Pengaplikasian For downto do

uses crt;
var a,b : integer;
begin
clrscr;
a:= 5;
for b:= a downto 1 do
begin
if b=1 then write(b*b,'=') else write (b*b,'+'); end;
write(a*11);
readln; end.



Hasil:

25+16+9+4+1=55


Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2

Contoh Program Paskal Pengaplikasian For do

uses crt;
var a: integer;
begin
clrscr;
for a:=1 to 10 do
begin
if (a mod 2=0) then write('-',a) else write('+',a);
end; readln; end.



Hasil

+1-2+3-4+5-6+7-8+9-10


Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2 

Contoh Program Paskal For Downto do

uses crt;
var i : integer;
begin
for i:=5 downto 3 do  write (i*2,' '); write(i);
readln; end.



Hasil:

10 8 6 3


Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2 

Contoh Program Paskal Repeat Until dan Inc

var K: integer;
begin
K:= 3;
repeat
write(K); inc(K);
until K>5;
readln; end.


Hasil:

345


Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2

Contoh Program Paskal Looping For do


uses crt;
var x,y:integer;
begin
for x := 1 to 2 do
begin
for y:= 1 to 2 do
write(y); write('ok'); end;
readln end.


Hasil:

12ok12ok


Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2

Contoh Program Paskal Pengaplikasian Delete dan Insert

uses crt;
var A,B,C : String[30];
begin
A:='BAHASA'; delete(A,3,2); Writeln(A);
Insert('ASAM',A,5);writeln(A);
readln; end.


Hasil:

BASA
BASAASAM


Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2

Contoh Program Array Pada Paskal

var A,B,C : Array [1..2,1..2] of integer; M,N: integer;
begin
A[1,1]:=1; A[2,1]:=0; B[1,1]:=1; B[2,1]:=0;
A[1,2]:=2; A[2,2]:=1; B[1,2]:=4; B[2,2]:=6;
for M:= 1 to 2 do
begin
for N:=1 to 2 do
begin
C[M,N]:=A[M,N]+B[M,N]; write (C[M,N],' ');
end;
writeln; end;
readln; end.


Hasil:
2 6
0 7


Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2

Contoh Program Paskal Pengaplikasian struktur While Do

var b,c : integer;
begin
b:=3; for c:=1 to 3 do
begin
while b<5 do
begin
write(b); inc(b);end;end;
readln; end.


Hasil:

34


Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2

Contoh Program Pengaplikasian Repeat Until

uses crt;
var i,tot : integer;
begin
clrscr;
i:=6; tot:=0;
repeat
tot:=tot+i; write(tot,' '); i:=i-1;
until i< 5;
readln;
end.


Hasil:
6 11



Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2

Contoh Program Paskal Menggunakan Length dan Copy


uses crt;
var A,B : string; E:integer;
begin
clrscr;
A:='bahasa';B:='pascal';
for E:= 1 to length (B) do
write(copy(A,E,1));
readln;
end.


Hasil:

bahasa



Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2

Contoh Program Paskal 2

uses crt;
var K: integer;
begin
clrscr;
K:=3;
while K<5 do
begin
inc(K);write(K,' ');
end;
readln;
end.

Hasil:

4 5



Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2

Contoh Program Paskal Repeat Until

uses crt;
var K:integer;
begin
clrscr;
K:=8;
repeat
dec(K);inc(K);write(K);
until K>5 ;
readln;
end.

Hasilnya sebagai berikut :

8

Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2

Contoh Program If pada Paskal


var a,b,c: integer;
begin
a:=45; b:= 18;
if a>=b then c:= a div b else c:= a mod b;
write(c);
readln;
end.


Hasilnya adalah :

2


Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2

Contoh Program Paskal 1



uses crt;
var a:integer;
begin
clrscr;
for a:= 1 to 2 do
writeln('ujian');writeln('tengah');writeln('semester');
readln;
end.


Hasil:

ujian
ujian
tengah
semester

Sumber : Pra UTS ATA 2011//2012 Algoritma & Pemprograman 2

Minggu, 06 Mei 2012

Contoh Looping pada Program Pascal Tiga Variabel 4

uses crt;
var a,b,c : integer;
begin
clrscr;
for a:= 1 to 5 do
  begin
  for b:= 1 to 5 do
  begin
  if(a mod 2)=1 then
  if(b mod 2)=1 then
  write(b,'  ');
  if(a mod 2)=0 then
  if (b mod 2)=0 then
  write('  ',b);
  end;
  writeln;
  end;
  readln;
  end.





Outputnya adalah:

1  3  5
  2  4
1  3  5
  2  4
1  3  5

Contoh Looping pada Program Pascal 3 variabel 3

uses crt;
var a,b,c : integer;
begin
clrscr;
c:=0;
for a:=4 downto 1 do
begin
for b:= 1 to a do
begin
c:=c+1;
write(c,' ');
end;
writeln;
end;
readln;
end.

Outputnya adalah:

1 2 3 4
5 6 7
8 9
10

Contoh Looping Program Pascal Tiga Variable 2

uses crt;
var a,b,c : integer;
begin
clrscr;
c:=10;
for a:=1 to 4 do
begin
for b:= 1 to a do
begin
c:=c-1;
write(c,' ');
end;
writeln;
end;
readln;
end.

Outputnya adalah:

9
8 7
6 5 4
3 2 1 0

Contoh Looping Pada Pascal Tiga Variable

uses crt;
var a,b,c : integer;
begin
clrscr;
c:=0 ;
for a:=1 to 4 do
begin
for b:= 1 to a do
begin
c:=c+1;
write(c,' ');
end;
writeln;
end;
readln;
end.

Maka Outputnya Sebagai berikut:

1
2 3
4 5 6
7 8 9 10