Skip to content

Latest commit

 

History

History
25 lines (19 loc) · 369 Bytes

Day 9_ Recursion.md

File metadata and controls

25 lines (19 loc) · 369 Bytes

Recursive Method for Calculating Factorial #include using namespace std;

int factorial(int n);

int main() { int n;

cout << "Enter a positive integer: ";
cin >> n;

cout << "Factorial of " << n << " = " << factorial(n);

return 0;

}

int factorial(int n) { if(n > 1) return n * factorial(n - 1); else return 1; }