[英]Why does printf not work in my program (Tried flushing)
I learned Objective-C before C and now that I am going back to C, I don't understand why the printf()
inside the loops does not work? 我在C之前学过Objective-C,现在回到C了,我不明白为什么循环内的
printf()
不起作用? Could someone advise me? 有人可以建议我吗?
The program is the first challenge in the book "Programming Challenges" By Skiena and Revilla if anyone is wondering. 如果有人想知道的话,该程序是Skiena和Revilla撰写的“ Programming Challenges”一书中的第一个挑战。
#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;
}
counter == (secondInt - inputInt)
您想要!=或<
尝试这个
for (int counter = 0; counter < (secondInt - inputInt); counter++ ) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.