Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int recursiveFact(int n) {
- return n ? n * recursiveFact(n - 1) : 1;
- }
- int iterFact(int n) {
- int res = 1;
- while (n) {
- res *= n;
- n--;
- }
- return res;
- }
- int main() {
- int n;
- cin >> n;
- cout << "Recursive Factorial: " << recursiveFact(n) << endl;
- cout << "Iterative Factorial: " << iterFact(n) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement