编码
int cycle_length(int i, int j) {
int cycleLength = 0;
for (int k = i; k <= j; k++) {
cout << algorithm(k) << endl;
if (algorithm(k) > cycle_length) {
cycleLength = algorithm(k);
}
}
return cycleLength;
}
ISO C++ forbids comparison between pointer and integer [-fpermissive]
我在这一行得到了这个错误if ( algorithm(k) > cycle_length)
。
但是,相同的代码如何在main()
?? 这个错误是什么意思???
添加 的算法是一个接受整数输入并返回整数的函数。
int algorithm(int number1) {
int counter = 1, number = number1;
do {
if (number % 2 == 0) {
number = number / 2;
counter++;
} else {
number = (3 * number) + 1;
counter++;
}
} while (number != 1);
return counter;
}