Warning: fopen(/www/wwwroot/www.wendadaohang.com/data/md5_content_title/49/491281364049fd0795bd2c73c6292da9.txt): failed to open stream: No space left on device in /www/wwwroot/www.wendadaohang.com/inc/function.php on line 2468

Warning: flock() expects parameter 1 to be resource, bool given in /www/wwwroot/www.wendadaohang.com/inc/function.php on line 2469

Warning: fclose() expects parameter 1 to be resource, bool given in /www/wwwroot/www.wendadaohang.com/inc/function.php on line 2475
c语言有一个错误 - 55问答网

c语言有一个错误

这条c语句有一个错误,总是找不到,麻烦帮我找下。 以下是代码:

#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;
}

你好!

    

温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2017-10-11
#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;
}本回答被提问者和网友采纳
第2个回答  2013-11-18
#include <stdio.h>
int main ()//无需void
{
long int sum=0;//这才是长整形变量
int count;//无需赋值,但不为错,会被掩盖

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;
}
相似回答