第1个回答 2020-02-26
//用for
int
n;
int
result=1;
//在这里输入要计算阶乘的数n
for
(int
i
=
1;
i
<=
n;
i++)
{
result
*=
i;
}
//在这里输出结果result
//用while
int
n;
int
result
=
1;
//在这里输入要计算阶乘的数n
while
(n>0)
{
result
*=
n--;
}
//在这里输出结果result
//用do
while
int
n;
int
result
=
1;
//在这里输入要计算阶乘的数n
do
{
result
*=
n--;
}
while
(n
>
0);
if
(result
<
1)
{
result
=
1;
}
//在这里输出结果result