哪位大神能用c语言递归算法计算n的阶乘*(n-1) 的阶乘
发布网友
发布时间:2023-05-04 07:58
我来回答
共1个回答
热心网友
时间:2023-10-26 21:45
代码如下:
//#include "stdafx.h"//If the vc++6.0, with this line.
#include "stdio.h"
unsigned myfact(int n){
if(n==1 || n==0)
return 1;
return n*myfact(n-1);
}
int main(void){
int n;
unsigned x;
while(1){
printf("Input n(int 0<=n<n<9)\nn=");//*到8为不溢出
if(scanf("%d",&n),n>=0 && n<=8)
break;
printf("Overrun, enter again: ");
}
printf("%d! x %d! = %d\n",n,n-1,(x=myfact(n-1))*n*x);
return 0;
}