diff --git a/factorial.cpp b/factorial.cpp new file mode 100644 index 0000000..6cc67c2 --- /dev/null +++ b/factorial.cpp @@ -0,0 +1,23 @@ +#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; +} \ No newline at end of file