永发信息网

C语言for (int i=1;i<=count;i++)编译不通过。

答案:2  悬赏:0  手机版
解决时间 2021-02-25 06:46
  • 提问者网友:难遇难求
  • 2021-02-25 00:23
教科书上面照打出来的,但是编译不通过。求解。我用的Dev-C++.
#include
int main(void)
{
long sum=0L;
int count=0;
printf("\nEnter the number of intergers you want to sum :");
scanf("%d",&count);
for (int i=1;i<=count;i++)
sum+=i;
{
printf("\nTotal of the first %d numbers is %ld\n",count,sum);
return 0;
}
最佳答案
  • 五星知识达人网友:廢物販賣機
  • 2021-02-25 01:37
少了一个括号},
int main(void)
{
long sum=0L;
int count=0;
printf("\nEnter the number of intergers you want to sum :");
scanf("%d",&count);
for (int i=1;i<=count;i++)
sum+=i;
{
printf("\nTotal of the first %d numbers is %ld\n",count,sum);
return 0;
}
}
全部回答
  • 1楼网友:鸽屿
  • 2021-02-25 01:52
如果你用的是c的编译器(不是c++的),那么是不允许在for的()中声明变量类型的。把i在前面声明,()中只写i=1就行了……
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯