Fungsi dapat dibedakan dalam 2 kategori :
Predefined functions (function standard ) : Merupakan fungsi dasar yg telah
disediakan C++. Seperti strlen(), getch() dll
User-Defined functions : Fungsi yang dibuat oleh programer sendiri sesuai dengan
kebutuhan.
Contoh 1
/* File program : prak71.cpp */
#include<iostream>
using namespace std;
/* fungsi untuk mencetak garis dgn panjang n karakter */
void cetakgaris(int n)
{ int i;
for(i=0;i<=n;i++)
cout<<"-";cout<<"\n";
}
main()
{ cetakgaris(15);//pemanggilan fungsi
return 0;
}
Contoh 2
/* File program : prak72.cpp */
#include<iostream>
using namespace std;
int Luas(int x,int y)
{int hasil;
hasil =x*y;
return hasil;
}
main()
{ int p=0,l=0,k;
cout<<"Menghitung Luas Persegi 4"<<endl;
cout<<endl<<"Masukan Panjang : ";cin>>p;
cout<<endl<<"Masukan Lebar : ";cin>>l;
k=Luas(p,l);//pemanggilan fungsi
cout<<endl<<"Luas = "<< k;
return 0;
}
ABOUT THE AUTHOR
A web designer from India. And then you write some more information about yourself like this to fill out the space that is left.
0 komentar:
Posting Komentar