diff --git a/Substract.c b/Substract.c new file mode 100644 index 0000000..17a4da1 --- /dev/null +++ b/Substract.c @@ -0,0 +1,25 @@ +// Factorial of n = 1*2*3*...*n + +#include +using namespace std; + +int factorial(int); + +int main() { + int n, result; + + cout << "Enter a non-negative number: "; + cin >> n; + + result = factorial(n); + cout << "Factorial of " << n << " = " << result; + return 0; +} + +int factorial(int n) { + if (n > 1) { + return n * factorial(n - 1); + } else { + return 1; + } +}