/*
题目:提示用户输入一个正整数n,计算并输出n的阶乘结果:1*2*3*…*n
*/
#include <stdio.h>
int JieCheng(int n)
{
if (n == 1)
{
return 1;
}
return n * JieCheng(n -1);
}
int main()
{
int n = 0;
int result = 0;
while(n <= 0)
{
printf("请输入一个正整数:\n");
scanf("%d",&n);
if ( n <= 0)
{
printf("输入有误,不是正整数,请重新输入!\n");
}
}
result = JieCheng(n);
printf("%d! = %d\n",n,result);
return 0;
} |
|