-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Function.cpp
73 lines (57 loc) · 1.38 KB
/
Function.cpp
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//Yogi Arif Widodo creator deyawman.net scode.id yogi-aw.id
#include <iostream>
//Program_mencari_nilai_max(tertinggi)
using namespace std;
//function declaration
/*
A function declaration has the following parts -
return_type function_name( parameter list );
defined funtion max()
int max(int num1, int num2);
parameter names are not important in function declaration only
their type is required , so following is also valid declaration
int max(int, int);
*/
//----------------------------------
/*
// calling a function
//-----------------------------------
int max(int num1, int num2);
int main()
{
int a = 1000;
int b = 2000;
int yog;
yog = max(a,b);
cout <<"max value is : " <<yog <<endl;
}
int max(int num1, int num2){
int result;
if (num1 > num2)
result = num1;
else
result = num2;
return result;
}
*/
// default value for parameters
//-----------------------------------
int sum(int a,int b=20){
int result;
result = a - b;
return result;
}
int main(){
int a = 100,b = 200;
int result;
// calling a function to add the value
result = sum(a,b);
cout <<"total value is : " <<result <<endl;
// calling a function again as follows
//menambahkan nilai local var a dengan function declaration b
result = sum(a);
cout <<"total value is : " <<result <<endl;
//kebalikanya yang di atas
result = sum(b);
cout <<"Total value is : " <<result <<endl;
}