Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <math.h>
  4. #include <stdlib.h>
  5.  
  6. int factorial (int num);
  7.  
  8. int main() {
  9.  
  10. int n;
  11. printf("Enter number to calculate factorial: ");
  12. scanf("%d",&n);
  13. printf("\n%d",factorial(n));
  14.  
  15. return 0;
  16. }
  17.  
  18. int factorial (int num) {
  19.  
  20. if ( num <= 1 ) return 1;
  21. else return num * factorial ( num - 1 );
  22.  
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement