C语言代码 任意整数的阶乘 实习用的 谢谢了 20分

来源:百度知道 编辑:UC知道 时间:2024/05/31 22:27:19
最近实习 ~~C语言很褴没办法了

#include <stdio.h>

int main()
{
int n;
printf("please enter the number:(numbers only)\n");
scanf("%d",&n);
int i;
long fact;

fact=n;
for(i=1;i<n;i++)
{
fact*=i;
}
printf("The factorial of %d is %ld.\n",n,fact);

fact=n;
i=1;
while(i<n)
{
fact*=i;
i++;
}
printf("The factorial of %d is %ld.\n",n,fact);
fact=n;
i=1;
do{
fact*=i;
i++;
}while(i<n);
printf("The factorial of %d is %ld.\n",n,fact);

}

已经调试过了,在GCC下面正确编译,在TC下面一定没有问题。

用了三种方法实现。
只需要输入阶乘的数n就行了。

#include <stdio.h>

int jieceng(int);

main(){
int i;
printf("请输入一个正整数:\n");
scanf("%d",&i);
if(i<=0){
printf("输入不合法,程序退出\n");
return 0