Advertisement
volkovich_maksim

factorial recursive

Sep 10th, 2016
351
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.49 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. long int fact(long int n)
  4. {
  5.    long int f = 1;
  6.    if (n > 0)
  7.       f = n*fact(n-1);
  8.    return f;
  9. }
  10.  
  11. int main(void)
  12. {  
  13.    long int n;
  14.    int qualifier = 1;
  15.    while (qualifier == 1 || qualifier == 0)
  16.    {
  17.       qualifier = scanf("%ld", &n);
  18.       if (qualifier == 1 && n >= 0)
  19.          {
  20.             printf("%ld\n", fact(n));
  21.          }
  22.       if (qualifier == 1 && n < 0)
  23.          {  
  24.             printf("wrong type\n");
  25.          }
  26.    }
  27.    return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement