#include <iostream>
using namespace std;
int main ()
{
//If a triangle has a perimeter of 9 units, how many iterations(each iteration is 4/3 as much) would it take to obtain a perimeter of 100 units? (or as close to 100 as you can get?)
double p = 9; int it = 0;
for(p; p < 100; p = p * 4/3){
cout << p << endl;
it++;
}
cout << p << endl;
cout << it << endl;
system ("PAUSE");
return 0;
}
因此,对于我正在做的一个数学项目,如果在每次迭代期间将周长增加 4/3 倍,我必须计算出周长为 9 达到 100 需要多少次迭代。当我像上面那样编写代码时,输出很好,但是如果我改变
for(p; p < 100; p = p * 4/3)
到
for(p; p < 100; p *= 4/3)
我得到没有意义的输出。我误解了 *= 运算符吗?我需要括号吗?