- #include <stdio.h>
- float fac(int n)
- {
- float f;
- if(n < 0)
- printf("n < 0, error!");
- else
- if(n == 0 || n == 1)
- f = 1;
- else
- f = fac(n - 1) * n;
- return f;
- }
- int main(void)
- {
- int n;
- float y;
- printf("input a integer:");
- scanf("%d", &n);
- y = fac(n);
- printf("%d!=%-20.0f\n", n, y);
- return 0;
- }
递归求阶乘
最新推荐文章于 2024-04-26 21:21:57 发布