dzungchaos

C++ "Đệ quy Giai thừa"

Nov 6th, 2019
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.19 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. long fact(int n){
  5.     if (n == 0) return 1;
  6.     else return n  * fact(n - 1);
  7. }
  8.  
  9. int main(){
  10.     int n;
  11.     cin >> n;
  12.     cout << fact(n);
  13.     return 0;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment