Contoh Method dan Function pada C++

#include <conio.h>
#include <iostream>

using namespace std;

void kali(){
int a,b,hasil;
cout<<"Masukkan nilai 1 :";
cin>>a;
cout<<"Masukkan nilai 2 :";
cin>>b;
hasil=a*b;
cout<<"Hasil kali : "<<hasil<<endl;}

double bagi(){
int c,d; float result;
cout<<"Masukkan nilai 1 : ";
cin>>c;
cout<<"Masukkan nilai 2 : ";
cin>>d;
result=c/d;
cout<<"Hasil bagi = ";
return result;}

main()
{
cout<<bagi()<<endl;
kali();
cout<<endl;

getch();
}

Selamat Mencoba!!! (^_^)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s