csansoon

P5.01 P12509 recursive factorial

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