#include <iostream> using namespace std; int Factorial(int n){ if(n == 0 || n == 1) return 1; return n * Factorial(n-1); } void CalculateFactorial(int n){ if(n == 0 || n == 1){ cout << "1"; return; } int ans = Factorial(n); cout << ans; } int main() { int n; cout << "Enter a number: "; cin >> n; cout << "Factorial of " << n << ": "; CalculateFactorial(n); return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter