mhdew

Factorial using recursion

Dec 22nd, 2017
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.22 KB | None | 0 0
  1. #include<stdio.h>
  2.  
  3. int fact(int n)
  4. {
  5. if(n!=0){
  6. return n*fact(n-1);
  7. }
  8. else
  9. return 1;
  10. }
  11.  
  12. int main()
  13. {
  14. int n;
  15.  
  16. scanf("%d", &n);
  17.  
  18. printf("%d\n", fact(n));
  19.  
  20. return 0;
  21. }
Advertisement
Add Comment
Please, Sign In to add comment