Created
December 27, 2013 12:52
-
-
Save novnan/8146622 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 用递归法计算n! | |
#include <stdio.h> | |
long factorial (int n) | |
{ | |
long f; | |
if(n <= 1) f = 1; | |
else f = n * factorial(n - 1); | |
return(f); | |
} | |
void main() | |
{ | |
int n; | |
long y; | |
printf("\ninput a integer number:\n"); | |
scanf("%d", &n); | |
y = factorial(n); | |
printf("%d != %ld\n", n, y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment