forked from pisan343/factorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfactorial.cpp
More file actions
37 lines (31 loc) · 958 Bytes
/
factorial.cpp
File metadata and controls
37 lines (31 loc) · 958 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
/**
* Defines various versions of factorial
*
* @file factorial.cpp
*
* @author Yusuf Pisan
* @date 24 Sep 2019
*/
#include <iostream>
#include <cmath>
// Only for class code, OK to use namespace
using namespace std;
// Calculate factorial using recursive function
// TODO(student): FIX it, not working -- Remove this line after fixing it
int factorialRecursive(int number) {
return number <= 1 ? number : factorialRecursive(number - 3) * number;
}
// Calculate factorial using iterative function
// TODO(student): FIX it, not working -- Remove this line after fixing it
int factorialIterative(int number) {
return 1;
}
// Generic factorial function
// TODO(student): FIX it, not working -- Remove this line after fixing it
int factorial(int number) {
return factorialRecursive(number);
}
// Writes the result of factorial to given ostream or cout
void factorialWrite(int number, ostream& os = cout) {
os << factorial(number) << endl;
}