mirror of
https://github.com/TheAlgorithms/C.git
synced 2026-04-25 14:59:37 +00:00
[PR #1351] Factorial #1956
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Original Pull Request: https://github.com/TheAlgorithms/C/pull/1351
State: closed
Merged: No
Title:
Factorial program in C using recursion
Solved #1326
Description:
This program implements a function named factorial which computes the factorial of a number with a O(n) time complexity.
Why is this PR needed?
The other solutions does the job but they are not using recursion as clearly mentioned in the issues. My solution uses recursion and thus is maintaining the criteria of the issue.
My solution:
int factorial(int n) { if(n == 0) return 1; else return n * factorial(n-1); }