Introduction to Recursion
#include <bits/stdc++.h>
using namespace std ;
int fact(int n){
if (n < 0) return -1 ;
if (n==0) return 1;
int small_ans = fact(n-1);
return n*small_ans ;
}
int main (){
int n ;
cin >> n ;
int ans = fact(n);
cout << ans << '\n';
return 0;
}
Comments
Post a Comment