Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /************************************/
- /** 20140506 Factorial **/
- /** Maker : Yan **/
- /** E-Mail : [email protected] **/
- /** Date : 2014/05/26 am.11:12 **/
- /************************************/
- #include <stdio.h>
- #include <stdlib.h>
- int factorial(int, int);
- void main()
- {
- printf("Enter a number of factorial: ");
- int input = 0, sum = 1;
- scanf("%d", &input);
- printf("Factorial results = %d.\n", factorial(input, sum));
- system("pause");
- }
- int factorial(int input, int sum)
- {
- if(input >= 1)
- {
- sum = sum * input--;
- factorial(input, sum);
- }
- else
- {
- return sum;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment