废话不多看代码:
for实现:
int main()
{int a = 0;int i = 0;scanf("%d", &a);int j = a; for (i = 1; i < a; i++){j = j * i;}printf("%d", j);return 0;
}
while实现:
int main()
{int a = 1;int b = 0;int num = 0;scanf("%d", &b);num = b;while (a < b){num = num * a;a++;}printf("%d", num);return 0;
}
do...while实现
int main()
{int a = 0;int b = 1;int c = 0;scanf("%d", &a);c = a;do{c = c * b;b++;} while (b < a);printf("%d", c);return 0;
}
当弄明白一个时,不妨试试其他的实现方式。
2022.2.9
本文链接:https://my.lmcjl.com/post/5685.html
展开阅读全文
4 评论