Holey_yan

20140506_KUAS_VisualC++_Factorial

May 6th, 2014
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. /************************************/
  2. /** 20140506 Factorial             **/
  3. /** Maker  : Yan                   **/
  4. /** E-Mail : [email protected] **/
  5. /** Date   : 2014/05/26 am.11:12   **/
  6. /************************************/
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10.  
  11. int factorial(int, int);
  12.  
  13. void main()
  14. {
  15.     printf("Enter a number of factorial: ");
  16.     int input = 0, sum = 1;
  17.     scanf("%d", &input);
  18.     printf("Factorial results = %d.\n", factorial(input, sum));
  19.     system("pause");
  20. }
  21.  
  22. int factorial(int input, int sum)
  23. {
  24.     if(input >= 1)
  25.     {
  26.         sum = sum * input--;
  27.         factorial(input, sum);
  28.     }
  29.     else
  30.     {
  31.         return sum;
  32.     }
  33. }
Advertisement
Add Comment
Please, Sign In to add comment