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#include <iostream>
2
3using namespace std;
4
5void function(){
6 cout << "I am a function!" << endl;
7}
8
9int main()
10{
11 function();
12
13 return 0;
14}
1#include <iostream>
2#include <stdlib.h>
3#include <iomanip>
4#include <fstream>
5using namespace std;
6
7void function_one(double, double, double);
8
9int main() {
10 double r1 = 1.0;
11 double r2 = 2.0;
12 double x = 0.0;
13 function_one(r1, r2, x);
14 return 0;
15}
16
17void function_one(double rmin, double rmax, double x0) {
18 cout << "Function got called" << endl;
19}
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