Tugas 2: Program-program pada Pascal



Type data Sederhana
A. Integer
Contoh :
program nilai_m;
uses winCrt;
var m : integer;
Begin
                write('masukan nilai m:');readln(m);
                writeln('Nilai yg anda masukan adalah:',m);
                readln;
end.



B. Real
Contoh :
Program celcius_ke_fahrenheit;
uses wincrt ;
var
   c : real ;
   f : real ;
begin
     writeln ('Program Konversi Suhu Celcius Ke Fahrenheit');
     writeln ;
     write ('Masukkan Suhu Dalam Celcius : ');
     readln (c) ;
     f:=(9/5)*c+32;
     writeln ;
     writeln ('Jadi Suhu Dalam FAHRENHEIT : ',f:0:0) ;
end.

Contoh :
Program karakter ;
uses winCrt;
var G:char;
begin
 writeln(‘G');
end.



Program Boolean2;
Uses WinCrt;
var tokka : boolean;
pink: String;
kode : String;
jawab : char;
Begin
                Write(‘masukkan kode : ');
                readln (kode);
                Write(‘apakah kamu menyukai pink ?(Y/T) : ');
                readln(jawab);
                if (jawab ='Y') or (jawab='y') then tokka := true
                else tokka := false;
                if (tokka= False) then
                Writeln('Berarti anda pria')
                else
                Writeln('Berarti anda wanita')
End.


Type data majemuk
A. String
Contoh program :
                Program data_diri;
                uses winCrt;
                var nama, nim, alamat, jurusan :string;
                begin
                                writeln('-------------------------------');
                                 writeln('---------Data Diri----------');
                                 writeln('-------------------------------');
                                Write('Masukkan nama anda :'); readln(nama);
                                write('Masukkan nim anda :'); readln(nim); 
                                write('Masukkan alamat anda :'); readln(alamat);
                                write('Masukkan jurusan anda :'); readln(jurusan);
                                writeln;
                end.'


OPERATOR
    1. Operator assignment
Contoh :
                Program assignment;
                                Uses winCrt;
Var
                                                x: integer;
                                                y: integer;
                                                q: integer;
                                Begin
                                                 x := 30;
                                                 y := 20;
                                                q:=x-y;
                                                  write('nilai hasil=',q);
                                                readln;
                                end.


2. Operator Aritmatika
Contoh :
Program Aritmatika;
Uses winCrt;
Var
g, h: integer;
Begin
Clrscr;
Writeln('#########################');
Writeln('########ARITMATIKA#########’);
Writeln('#########################');
Write ('nilai G  : '); readln (g);
Write (' nilai H : '); readln (h);
Writeln;
Writeln ('g+h = ' , g+ h);
Writeln ('g - h = ' , g - h);
Writeln ('g* h=' , g* h);
Writeln ('g / h = ' , g / h);
Writeln ('g div h = ' , g div h);
Writeln ('g mod h = ' , g mod h);
Readln;
End.

0 komentar: