我不完全确定从这个程序开始。我刚刚介绍了循环并完成了几个简单的循环。这个问题对我来说没有意义。基本上应该阅读
answer is 3
answer is 12
answer is 60
answer is 360
answer is 2520
answer is 20160
我可以让它读到这个,但只能通过硬编码...我是否使用while语句?如果声明?别的陈述?我迷路了,已经尝试了大约一个小时。
答案 0 :(得分:4)
问题可以通过一个for
循环解决,如下所示。
int Product = 1;
for (int i = 3; i <= 8; i++)
{
Product = Product * i;
// if desired, do something useful with Product
}
答案 1 :(得分:0)
这遵循一种模式
3*4 = 12
(3*4)*5 = 12 * 5 = 60
(3*4*5)*6 = 60 * 6 = 360
(3*4*5*6)*7 = 360 * 7 = 2520
(3*4*5*6*7)*8 = 2520 * 8 = 20160
C ++中的代码
int result = 1;
for(int i =3; i<=8;i++)
{
result = result * i;
cout<<"answer is"<<result;
}
答案 2 :(得分:0)
int out = 1;
for (int i = 3; i < 9; ++i)
{
out *= i;
cout << out << endl;
}
答案 3 :(得分:-1)
int main() {
int num = 3;
int mult = (num + 1);
while (num < 20000) {
cout << "The answer is ";
cout << num;
cout << endl;
num = (num * mult);
}
cout << endl;
return 0;
}
这就是我所拥有的,我只是得到3分,12分,48分,192分等等。