Contoh Program Fungsi pada C++
// Menampilkan pesan
#include <iostream>
#include <conio>
void printmessage ()
{
cout << "I'm a function!";
}
void main ()
{
printmessage ();
getch();
}
#include <iostream>
#include <conio>
void printmessage ()
{
cout << "I'm a function!";
}
void main ()
{
printmessage ();
getch();
}
Contoh Program Fungsi pada Pascal
uses crt;
function Hitung (X, Y, Z : Byte):
Byte;
Begin
Z := X + Y;
Writeln ('ilai X = ',X);
Writeln ('Nilai Y = ',Y);
Writeln ('Nilai Z = ', Z);
End;
Var
A, B, C : Byte;
Begin
clrscr;
A := 5; B:= 7; C:=3;
Hitung (A, B, C);
Writeln ('Nilai A = ',A,'Nilai B =
',B,'Nilai C = ',C);
Readln;
End.
Contoh Program Prosedur pada C++
#include<iostream.h>
#include<conio.h>
int addition (int a, int b){
int r;
r=a+b;
return (r);
}
void main ()
{
int z;
z = addition (5,3);
cout <<
"The result is " << z;
getch();
}
Contoh Program Prosedur pada Pascal
program Lsegitiga;
uses crt;
var
i,n:integer;
a,t:real;
procedure
hitungLuassegitiga(alas,tinggi:real);
var
luas:real;
BEGIN
luas:=(alas*tinggi)/2;
writeln('luas segitiga=',luas:10:2);
END;
BEGIN
Clrscr;
write ( ' banyaknya segitiga ?');
readln(n);
for i:=1 to n do
BEGIN
write(' panjang alas segitiga?');
readln(a);
write('tinggi segitiga?');
readln(t);
hitungluassegitiga(a,t);
END;
END.
0 komentar:
Posting Komentar