比较下面两个代码的区别,分不清,望指教
# include <stdio.h> int main()
{
int n, i, sum = 0;
while(scanf("%d", &n)!=EOF)
{
for(i=1; i<=n; ++i)
sum = sum + i;
printf("%d\n\n", sum);
sum = 0;
}
return 0;
}
# include <stdio.h>
int main()
{
int n, i, sum = 0;
while(scanf("%d", &n)!=EOF)
{
for(i=1; i<=n; ++i)
{sum = sum + i;
sum = 0;}
printf("%d\n\n", sum);
}
return 0;
}
[此贴子已经被作者于2016-3-16 22:48编辑过]