代码块编译器不显示输出
Codeblocks compiler not displaying output
我正在尝试解决下面的这个问题。据我所知,一切在逻辑上和语法上都是正确的。但是,当我点击运行时,弹出黑色命令window,它显示了问题1-4的答案(那些因为不相关而被省略,并且问题5被裁掉了),但是问题 6 函数没有任何反应,而且我从来没有得到“进程返回 0 (0x0) 执行时间:xxxx s”。是我做错了什么,还是编译器?
注意:我不是要答案。我只想知道为什么不显示。
/* problem 6 Find the difference between the sum of the squares of the first 100 numbers and the square of the sum*/
void problem6()
{
int sum_of_squares;
int square_of_sums;
int counter;
int answer;
int x;
for(x=1; x=100; x++)
{
sum_of_squares += (x*x);
counter += x;
}
square_of_sums = (counter*counter);
answer = square_of_sums - sum_of_squares;
printf("Problem 6 answer: %d", answer);
}
/* problem5(); */
problem6();
(=) 是赋值运算符。您的条件应该是 (x<=100) 或 (x!=101)。而且您还没有用任何值初始化 sum_of_squares、square_of_sums 和计数器,因此它们包含垃圾值。
void problem6()
{
int sum_of_squares=0;
int square_of_sums=0;
int counter=0;
int answer;
int x;
for(x=1; x<=100; x++)
{
sum_of_squares += (x*x);
counter += x;
}
square_of_sums = (counter*counter);
answer = square_of_sums - sum_of_squares;
printf("Problem 6 answer: %d", answer);
}
我正在尝试解决下面的这个问题。据我所知,一切在逻辑上和语法上都是正确的。但是,当我点击运行时,弹出黑色命令window,它显示了问题1-4的答案(那些因为不相关而被省略,并且问题5被裁掉了),但是问题 6 函数没有任何反应,而且我从来没有得到“进程返回 0 (0x0) 执行时间:xxxx s”。是我做错了什么,还是编译器? 注意:我不是要答案。我只想知道为什么不显示。
/* problem 6 Find the difference between the sum of the squares of the first 100 numbers and the square of the sum*/
void problem6()
{
int sum_of_squares;
int square_of_sums;
int counter;
int answer;
int x;
for(x=1; x=100; x++)
{
sum_of_squares += (x*x);
counter += x;
}
square_of_sums = (counter*counter);
answer = square_of_sums - sum_of_squares;
printf("Problem 6 answer: %d", answer);
}
/* problem5(); */
problem6();
(=) 是赋值运算符。您的条件应该是 (x<=100) 或 (x!=101)。而且您还没有用任何值初始化 sum_of_squares、square_of_sums 和计数器,因此它们包含垃圾值。
void problem6()
{
int sum_of_squares=0;
int square_of_sums=0;
int counter=0;
int answer;
int x;
for(x=1; x<=100; x++)
{
sum_of_squares += (x*x);
counter += x;
}
square_of_sums = (counter*counter);
answer = square_of_sums - sum_of_squares;
printf("Problem 6 answer: %d", answer);
}