我在C之前学过Objective-C,现在我回到C,我不明白为什么循环中的printf()
不起作用?有人可以告诉我吗?
如果有人想知道,该计划是Skiena和Revilla的“编程挑战”一书中的第一个挑战。
#include <stdio.h>
#include <stdbool.h>
static int inputInt;
static int secondInt;
int returnCycleNumber(int givenNumber);
int returnCycleNumber(int givenNumber) {
bool initial = true;
int counter = 1;
do
{
if (givenNumber % 2 != 0)
{
givenNumber = givenNumber * 3 + 1;
counter = counter + 1;
printf("\n%i", givenNumber);
}
else
{
givenNumber = givenNumber / 2;
counter = counter + 1;
printf("\n%i", givenNumber);
}
if (givenNumber == 1) {
initial = false;
}
} while (initial == true && givenNumber > 1);
return counter;
}
int main(int argc, const char * argv[])
{
scanf("%i %i", &inputInt, &secondInt);
fflush(stdout);
int arrayCount[secondInt];
for (int counter = 0; counter == (secondInt - inputInt); counter++ ) {
arrayCount[counter] = returnCycleNumber(inputInt + counter);
}
printf("\n%i", arrayCount[1]);
return 0;
}
答案 0 :(得分:3)
counter == (secondInt - inputInt)
你想要!=或&lt;
答案 1 :(得分:0)
试试这个
for (int counter = 0; counter < (secondInt - inputInt); counter++ ) {