Factorial in C By Recursion


SUBMITTED BY: kaushal1981

DATE: Feb. 17, 2017, 1:58 a.m.

FORMAT: Text only

SIZE: 350 Bytes

HITS: 980

  1. #include <stdio.h>
  2. long int multiplyNumbers(int n);
  3. int main()
  4. {
  5. int n;
  6. printf("Enter a positive integer: ");
  7. scanf("%d", &n);
  8. printf("Factorial of %d = %ld", n, multiplyNumbers(n));
  9. return 0;
  10. }
  11. long int multiplyNumbers(int n)
  12. {
  13. if (n >= 1)
  14. return n*multiplyNumbers(n-1);
  15. else
  16. return 1;
  17. }

comments powered by Disqus