-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfunctions.cpp
More file actions
42 lines (36 loc) · 1008 Bytes
/
functions.cpp
File metadata and controls
42 lines (36 loc) · 1008 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <iostream>
using namespace std;
//This is function declaration, to avoid the overhead of forward referencing.
int max(int,int);
//This is the main function. Every program has a main function.
int main(int argc, char const *argv[]){
int num1;
int num2;
int maximum;
cout << "Enter a number: ";
cin >> num1;
cout << "Enter another number: ";
cin >> num2;
//This is function calling, and the value returned is stored in variable maximum.
maximum = max(num1,num2);
cout << "Maximum of " << num1 << " and " << num2 <<" is "<<maximum;
return 0;
}
//This is function definition.
/*
We can have default parameters as well. Like we can set num2 = 10 as default. Unless specified, it will take value of num2 as 10.
*/
int max(int num1,int num2){
/*
Objective : To find maximum of two numbers.
Parameters : num1 - integer type, number 1
num2 - integer type, number 2
Return value : Maximum of two numbers.
*/
if (num1 > num2){
return num1;
}
else{
return num2;
}
}