-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.cpp
45 lines (37 loc) · 858 Bytes
/
functions.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
/*******************************************
Fourth example: functions.cpp
A simple example for function calls:
- function overload,
- recursive calls.
Chensong Zhang Feb/08/2011.
********************************************/
#include <iostream>
using namespace std;
// mult function for int
int mult (int a=0, int b=0)
{
return (a*b);
}
// mult function reloaded for double
// We can use template to do this to make it more general!!!
double mult (double a=0.0, double b=0.0)
{
return (a*b);
}
// recursive call
long factorial (long a)
{
if (a > 1)
return (a * factorial (a-1));
else
return (1);
}
int main ()
{
double x=5, y=2;
int n=5, m=2;
cout << scientific << mult (x,y) << endl;
cout << scientific << mult (n,m) << endl;
cout << scientific << factorial ( mult (n,m) ) << endl;
return 0;
}