为什么给变量赋值的语句改变位置后运行结果不一样啊
#include <stdio.h>int main (void)
{
int n, number, summary = 0, counter;
for (counter = 1; counter <= 5; counter++)
{
printf ("what number do you want? ");
scanf ("%i", &number);
for (n = 1; n <= number; n++)
summary += n;
printf ("The number %i is %i\n\n", number, summary);
getch();
}
return 0;
}
为什么上面的运行结果是错的 把summary = 0这个给变量赋值这个语句写到scanf函数下面的一行结果就没错误啊?
int n, number, summary, counter;
scanf ("%i", &number);
summary = 0;
for (n = 1; n <= number; n++)
改成这样就没问题 请问为什么?