1 / 10

Procedure & Function

Procedure & Function. Sub Program. Pengenalan Sub Program. Procedure & Function (1).

webb
Download Presentation

Procedure & Function

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Procedure & Function Sub Program

  2. Pengenalan Sub Program

  3. Procedure & Function (1) • Procedure dan Function adalah suatu program terpisah dalam blok sendiri yang berfungsi sebagai sub-program (modul program) yang merupakan sebuah program kecil untuk memproses sebagian dari pekerjaan program utama. • Procedure = Subprogram yang tidakmemberikan / mempunyainilaiakhir • Function = Subprogram yang memberikan / mempunyainilaiakhir

  4. Procedure & Function (2) PROCEDURE nama; PROCEDURE nama (formal parameter : jenis); FUNCTION nama : jenishasil; FUNCTION nama (formal parameter : jenis ) : jenis_hasil;

  5. Procedure non parameter program halo; uses wincrt; procedure coba; begin writeln('PASCAL'); end; begin write('halo '); coba; Readln; end. Definisi Procedure Program Utama Pemanggilan Procedure

  6. Procedure with parameter lokal Parameter Formal program loop; uses wincrt; procedure ulangi(karakter:char; jum:integer); var i:integer; begin for i:=1 to jum do write(karakter); writeln; end; begin ulangi('*‘,10); ulangi('#‘,3); ulangi('+‘,5); Readln; end. Parameter Lokal Definisi Procedure Parameter Aktual Program Utama

  7. Procedure with parameter global program loop; uses wincrt; var i:integer; procedure ulangi(karakter:char; jum:integer); begin for i:=1 to jum do write(karakter); writeln; end; begin ulangi('*‘,10); ulangi('#‘,3); ulangi('+‘,5); Readln; end. Parameter Global Definisi Procedure Pemanggilan Procedure Program Utama

  8. Latihan • Bagaimanamembuat program LUAS BIDANG DATAR denganmenggunakan Procedure??

  9. Function (1) program coba; uses wincrt; var x:integer; function tambah(a,b: integer): integer; begin tambah:= a + b; end; begin x:=tambah(2,3); write(x); readln; end. Parameter Global Definisi Function Program Utama

  10. Function (1) program coba2; uses wincrt; var p,q,a,b:integer; Function max (x,y : integer) : integer; Begin If x < y then max := y else max := x; End; begin write('input a: ');readln(a); write('input b: ');readln(b); p:=max(a,b); q:= max(a+b,a*b); writeln('p= ',p); writeln('q= ',q); readln; end.

More Related