其中N是用户传入的参数,其值不超过12。如果N是非负整数,则该函数必须返回N的阶乘,否则返回0。
#include "stdafx.h" int Factorial(const int N); int main() { int N, NF; scanf("%d", &N); NF = Factorial(N); if (NF) printf("%d! = %d\n", N, NF); else printf("Invalid input\n"); return 0; } int Factorial(const int N) { if (N<0) return 0; if (N == 0) return 1; return N * Factorial(N - 1); }
递归阶乘
最新推荐文章于 2023-03-03 00:32:31 发布