MeehoweCK

Untitled

Nov 5th, 2020
1,749
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. /* FUNCTIONS
  6.  
  7. returned_type name([arguments])
  8. {
  9.     body_of_the_function
  10. }
  11.  
  12. */
  13.  
  14. // a function which doesn't return any value and doesn't capture any arguments:
  15. void function1()
  16. {
  17.     cout << "The function has been called\n";
  18. }
  19.  
  20. // a function which doesn't return any value but it takes two arguments
  21. void sum(int a, int b)
  22. {
  23.     cout << a << " + " << b << " = " << a + b << endl;
  24. }
  25.  
  26. // a function which returns the result (double) and takes two arguments
  27. double divide(int a, int b)
  28. {
  29.     return 1.0 * a / b;
  30. }
  31.  
  32. int main()
  33. {
  34.     function1();
  35.  
  36.     sum(17, 18);
  37.     sum(5, 10);
  38.     sum(3, 12);
  39.  
  40.     int x = 100, y = 20;
  41.     sum(x, y);
  42.  
  43.     double result = divide(x, y);
  44.     cout << result << endl;
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment