Advertisement
ssr17

Factorial using Recursion

Sep 10th, 2016
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.32 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. long factorial (int n)
  4. {
  5.     if(n == 0)
  6.         return 1;
  7.     else
  8.         return (n * factorial(n-1));
  9. }
  10.  
  11. int main ()
  12. {
  13.     int n;
  14.     long f;
  15.  
  16.     printf("Enter the integer to find Factorial : ");
  17.     scanf("%d", &n);
  18.  
  19.     f = factorial(n);
  20.     printf("%d! = %ld",n,f);
  21.     return 0;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement