1// function example
2#include <iostream>
3using namespace std;
4
5int addition (int a, int b)
6{
7 int r;
8 r=a+b;
9 return r;
10}
1//first lets create a function
2/*void is for starting something, anything after void will be the name of your
3function which will be followed by () */
4void yourFunction() {
5//your code will be here, anything here will be the code in the yourFunction
6 cout << "Functions"
7}
8//now we have to go to our main function, the only function the compiler reads
9int main() {
10 myFunction(); //you call the function, the code we put in it earlier will be executed
11 return 0;
12}
1// function returning the max between two numbers
2
3int max(int num1, int num2) {
4 // local variable declaration
5 int result;
6
7 if (num1 > num2)
8 result = num1;
9 else
10 result = num2;
11
12 return result;
13}
14