注意17行for语句结尾的';',因为多写了个分号,找了好几种方法调试C源码,最后还是在for语句中加printf语句才发现这个分号
1.语法不熟
2.调试手段不够丰富
这是调试时的写法
以下是我写的答案,注释为调试用;
// 6.16.10
include <stdio.h>
int main(void)
{
int upperlimit = 7;
int lowerlimit = 6;
int init;
int sum = 0;
printf("Enter lower and upper integer limits: ");
scanf("%d %d", &lowerlimit, &upperlimit);
// scanf("%d", &lowerlimit);
// printf("%d %d
", lowerlimit, upperlimit);
while ( upperlimit > lowerlimit)
{
// upperlimit 是最大值,lowerlimit 是最小值
init = 0;
for (init = lowerlimit; init <= upperlimit; init++)
{
// printf("init is %d
", init);
// printf("lowerlimit is %d
", lowerlimit);
// printf("upperlimit is %d
", upperlimit);
sum = sum + init * init;
// printf("sum is %d
", sum);
}
printf("The sums of the squares from %d to %d is %d
", lowerlimit * lowerlimit,
upperlimit * upperlimit, sum);
sum = 0;
printf("The next set of limits: ");
scanf("%d %d", &lowerlimit, &upperlimit);
}
printf("Done
");
return 0;
}