下面这个程序有一个错误
#include <stdio.h>
int main (void){
long sum=0L;
int count=0;
printf("\nEnter the number of integers you want to sum:");
scanf("%d",&count);
for(int i=1; i <= count;i++)
sum +=i;
printf("\nTotal of the first %d number is %Ld\n",count,sum);
return 0;
}
改正:
#include <stdio.h>
int main (void)
{
long sum=0;
int count,i;
printf("\nEnter the number of integers you want to sum:");
scanf("%d",&count);
for( i=1;i<count||i==count;i++)
/* [Error] 'for' loop initial declarations are only allowed in C99 mode 我估计意思是在for()中定义变量,只能在C99标准里*/
sum +=i;
printf("\nTotal of the first %d number is %Ld\n",count,sum);
return 0;
}