Advertisement
gurumutant

Subprogram/Function Concept in C++

Aug 18th, 2019
329
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.58 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. // definisi fungsi dengan tipe void (Prosedur)
  6. void hello(int n=1) {
  7.     for(int i=1;i<=n;i++) {
  8.         cout << i << ". " << endl;
  9.         cout << "Hello world!" << endl;
  10.         cout << "Let's start the day with a cup of coffee" << endl;
  11.     }
  12. }
  13.  
  14. // definisi fungsi dengan tipe selain void (Fungsi)
  15. int tambah(int a, int b) {
  16.     int hasil;
  17.     hasil  = a + b;
  18.     return hasil;
  19. }
  20.  
  21. int main()
  22. {
  23.     hello();
  24.     hello(tambah(7,9));
  25.     cout << "hasil 7 ditambah 5 adalah " << tambah(7,5);
  26.     cout << endl;
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement