gurumutant icon

Subprogram/Function Concept in C++

gurumutant | PRO | 08/19/19 01:12:36 AM UTC | 0 ⭐ | 627 👁️ | Never ⏰ | []
C++ |

580 B

|

None

|

0 👍

/

0 👎

#include <iostream>
 
using namespace std;
 
// definisi fungsi dengan tipe void (Prosedur)
void hello(int n=1) {
    for(int i=1;i<=n;i++) {
        cout << i << ". " << endl;
        cout << "Hello world!" << endl;
        cout << "Let's start the day with a cup of coffee" << endl;
    }
}
 
// definisi fungsi dengan tipe selain void (Fungsi)
int tambah(int a, int b) {
    int hasil;
    hasil  = a + b;
    return hasil;
}
 
int main()
{
    hello();
    hello(tambah(7,9));
    cout << "hasil 7 ditambah 5 adalah " << tambah(7,5);
    cout << endl;
    return 0;
}

Comments