cin = masukan
cout = keluaran
void main = void; kosong, main; utama.
fungsi cpp : bsa dipakai program lain
void = tidak dipakai oleh program lain,
() = kosong, kalo dipake oleh program lain, maka di isi.
cout<< " # \n"
system ("pause")
}
Contoh_1 :
#include "iostream"
using namespace std;
void garis() { //deklarasi fungsi dengan nama garis
cout<<"---------------------\n";
}
void main () {
int i=0;
garis ();
cout<<"##### WELCOME TO MY CLASS #####\n";
garis();
for (i=1;i<=10;i++){
cout<<i*2-1<<endl;
}
system ("pause");
}
Contoh_2:
#include "iostream"using namespace std;
void ganjil() { //deklarasi fungsi
int i=0;
cout<<"10 BILANGAN GANJIL PERTAMA \n";
for (i=1;i<=10;i++){
cout<<" "<<i*2-1<<" "<<endl;
cout<<"-----------------------"<<endl;
}
cout<<"---------------------\n";
}
void genap() { //deklarasi fungsi
int i=0;
cout<<"10 BILANGAN GENAP PERTAMA \n";
for (i=1;i<=10;i++){
cout<<" "<<i*2<<" "<<endl;
cout<<"-----------------------"<<endl;
}
}
void main () {
cout<<"##### WELCOME TO MY CLASS #####\n";
ganjil();
genap();
system ("pause");
}
Contoh_3:
#include "iostream"
#include "iomanip"
using namespace std;
void garis (){ //deklarasi fungsi dengan nama garis
cout<<"---------------------------------\n";
}
void ganjil() { //deklarasi fungsi
cout<<"10 BILANGAN GANJIL PERTAMA \n";
for (int i=1;i<=10;i++){
cout<<setw(20)<<i*2-1<<endl;
garis();
}
}
void genap() { //deklarasi fungsi
cout<<"10 BILANGAN GENAP PERTAMA \n";
for (int i=1;i<=10;i++){
cout<<setw(20)<<i*2<<endl;
garis();
}
}
void main () {
int pilihan, maka ;
awal:
cout<<"##### WELCOME TO MY CLASS #####\n";
cout<<" 1. GENAP\n";
cout<<" 2. GANJIL\n";
cout<<" 3. EXIT\n";
cout<<" Masukkan pilihan (1/2/3) : ";cin>>pilihan;
if (pilihan==1){
ganjil();
goto awal;}
else if (pilihan==2){
genap();
goto awal;}
else if (pilihan==3){
exit;}
else{
cout<< "SALAH INPUT PILIHAN !!!\n";
goto awal;}
system ("pause");
}
1 komentar:
jadi inget jaman kuliah dulu :D
Posting Komentar
Tuliskan Komentar Disini..