MATERI-MATERI MATA KULIAH SISTEM INFORMASI STMIK MDP

Pasang Iklan Gratis Disini !!!

ads ads ads ads

Sabtu, 27 November 2010

Contoh Deklarasi Fungsi

. Sabtu, 27 November 2010

#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 3:
#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");
}

catt :untuk menambahkan spasi, maka :
ditambahkan #include "iomanip"
dan setw(20) // 20 bsa diganti tergantung berapa karakter

contoh :
#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 () {
cout<<"##### WELCOME TO MY CLASS #####\n";
ganjil();
genap();

system ("pause");
}

SEMOGA BERMANFAAT

0 komentar:

:)) ;)) ;;) :D ;) :p :(( :) :( :X =(( :-o :-/ :-* :| 8-} :)] ~x( :-t b-( :-L x( =))

Posting Komentar

Tuliskan Komentar Disini..

Related Posts Plugin for WordPress, Blogger...
 
{Sistem Informasi} is proudly powered by Blogger.com | Template by : Sukriyadi | sukriyadi.blogspot.com