我的第十七个代码
#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
int main()
{
int a = 1;
int b = 1;
int n = 1;
scanf("%d", &n);
while (a <= n)
{
b = a*b;
a++;
}
printf("%d\n", b);
return 0;
}//利用while循环计算n的阶乘
int main()
{
int a = 1;
int b = 1;
int n = 1;
scanf("%d", &n);
for (a = 1; a <= n; a++)
{
b = a*b;
}
printf("%d\n", b);
return 0;
};//利用for循环计算n的阶乘
int main()
{
int a = 1;
int b = 1;
int n = 1;
scanf("%d",& n);
do
{
b = a*b;
a++;
}
while (a <= n);
printf("%d\n", b);
return 0;
}//利用do……while循环计算n的阶乘
来源:51CTO
作者:大圣?
链接:https://blog.51cto.com/15100722/2633151