C程序调试时出现Program received signal SIGSEGV, Segmentation fault?
#include<stdio.h>intmain(){intn,hi[100],i=1,sum=0,step=0,count=0,ave;while(scanf("%d"...
#include<stdio.h>
int main(){
int n,hi[100],i=1,sum=0,step=0,count=0,ave;
while(scanf("%d",&n)!=EOF&&n!=0){
for(i=1;i<=n;i++){
scanf("%d",hi[i]);
sum+=hi[i];
}
ave=sum/n;
if(sum%n==0){
for(i=1;i<=n;i++){
if(hi[i]>ave)step+=hi[i]-ave;
}
}
else continue;
count++;
printf("Set #%d",count);
printf("The minimum number of moves is %d.\n\n",step);
step=0;
sum=0;
}
return 0;
} 展开
int main(){
int n,hi[100],i=1,sum=0,step=0,count=0,ave;
while(scanf("%d",&n)!=EOF&&n!=0){
for(i=1;i<=n;i++){
scanf("%d",hi[i]);
sum+=hi[i];
}
ave=sum/n;
if(sum%n==0){
for(i=1;i<=n;i++){
if(hi[i]>ave)step+=hi[i]-ave;
}
}
else continue;
count++;
printf("Set #%d",count);
printf("The minimum number of moves is %d.\n\n",step);
step=0;
sum=0;
}
return 0;
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询