Advertisement
sheredega

Task #14

Dec 10th, 2022
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.30 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int fac(int n) {
  5.     if (n == 0) {
  6.         return 1;
  7.     }
  8.     return fac(n-1) * n;
  9. }
  10.  
  11.  
  12. int main() {
  13.     cout << "Enter n: ";
  14.     int n;
  15.     cin >> n;
  16.     int result = fac(n);
  17.     cout << "Factorial of " << n << " is " << result;
  18.     return 0;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement