使用while循环求1~13的累乘的积
时间: 2024-03-09 12:49:42 浏览: 115
可以使用以下代码来求解:
```python
n = 1
i = 1
while i <= 13:
n *= i
i += 1
print(n)
```
在这个代码中,我们使用了一个 while 循环来累乘 1~13 的数,初始值设为 1,然后每次循环将当前的数乘以计数器 i,最后输出累乘的结果。
相关问题
while循环求累加累乘
以下是使用 while 循环求累加累乘的代码示例:
```python
# 求1到n的累加和
n = 10
sum = 0
i = 1
while i <= n:
sum += i
i += 1
print("1到{}的累加和为:{}".format(n, sum))
# 求1到n的累乘积
n = 5
product = 1
i = 1
while i <= n:
product *= i
i += 1
print("1到{}的累乘积为:{}".format(n, product))
```
关于 lua closure factory 的完整代码和中文加密,我需要更多的上下文和信息才能回答。
c语音他while循环1到100累乘
以下是C语言使用while循环计算1到100的累乘的代码:
#include <stdio.h>
int main() {
int i = 1;
long long int result = 1;
while (i <= 100) {
result *= i;
i++;
}
printf("1到100的累乘为:%lld", result);
return 0;
}
首先定义一个变量i和一个变量result,分别表示循环的计数器和累乘的结果。然后使用while循环,当i小于等于100时,执行循环体内的代码,即将i乘到result中,并将i加1。最后输出结果即可。