Skip to content

Instantly share code, notes, and snippets.

@novnan
Created December 27, 2013 12:52
Show Gist options
  • Save novnan/8146622 to your computer and use it in GitHub Desktop.
Save novnan/8146622 to your computer and use it in GitHub Desktop.
// 用递归法计算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