#include<stdio.h>
int main()
{
int n,counter=1,sum=0;
printf("请输入项数n\n");
scanf("%d",&n);
while(counter<=n);
{
sum=sum+counter*counter;
counter++;
}
printf("%d\n",sum);
return 0;
}
这段代码,不知怎的不给运行
#include<stdio.h>
int main()
{
int n,counter=1,sum=0;
printf("请输入项数n\n");
scanf("%d",&n);
while(counter<=n);
{
sum=sum+counter*counter;
counter++;
}
printf("%d\n",sum);
return 0;
}
这段代码,不知怎的不给运行
#include<stdio.h>
int main()
{
int n,counter=1,sum=0;
printf("请输入项数n\n");
scanf("%d",&n);
while(counter<=n)
{
sum=sum+counter*counter;
counter++;
}
printf("%d\n",sum);
return 0;
}
程序在while(counter<=n)后面多了个分号,导致counter不能自加永远也跳不出循环。把分号去掉就好了。
你用的什么编译器,我用vc6.0编过了
可能是编译器的问题啦