求教:为什么这个简单程序计算结果第二项(-10 -44 -10.000000)是错误的?
#include<stdio.h> void main()
{
int c[41],i[13],j,k=41,g=13;
float m,n,a=2.1,b=1.2;
printf("请输入(1)个整数: \n");
for(j=0;j<k;j++)
scanf("%d",&c[j]);
printf("\n");
for(j=0;j<g;j++)
scanf("%d",&i[j]);
printf("\n");
m=c[i[6]]-c[i[5]]+c[i[4]]-c[i[3]]-c[i[2]]+c[i[1]]-c[i[0]],n=i[6]-i[5]+i[4]-i[3]-i[2]+i[1]-i[0];
printf("%d ",c[i[6]]-c[i[5]]+c[i[4]]-c[i[3]]-c[i[2]]+c[i[1]]-c[i[0]]);
printf("%d ",i[6]-i[5]+i[4]-i[3]-i[2]+i[1]-i[0]);
if(n!=0)
printf("%f \n",m/n);
else
printf("\n");
m=c[i[7]]-c[i[6]]+c[i[5]]-c[i[4]]-c[i[3]]+c[i[2]]-c[i[1]],n=i[7]-i[6]+i[5]-i[4]-i[3]+i[2]-i[1];
printf("%d ",c[i[7]]-c[i[6]]+c[i[5]]-c[i[4]]-c[i[3]]+c[i[2]]-c[i[1]]);
printf("%d ",i[7]-c[i[6]]+i[5]-i[4]-i[3]+i[2]-i[1]);
if(n!=0)
printf("%f \n",m/n);
else
printf("\n");
m=c[i[8]]-c[i[7]]+c[i[6]]-c[i[5]]-c[i[4]]+c[i[3]]-c[i[2]],n=i[8]-i[7]+i[6]-i[5]-i[4]+i[3]-i[2];
printf("%d ",c[i[8]]-c[i[7]]+c[i[6]]-c[i[5]]-c[i[4]]+c[i[3]]-c[i[2]]);
printf("%d ",i[8]-i[7]+i[6]-i[5]-i[4]+i[3]-i[2]);
if(n!=0)
printf("%f \n",m/n);
else
printf("\n");
m=c[i[9]]-c[i[8]]+c[i[7]]-c[i[6]]-c[i[5]]+c[i[4]]-c[i[3]],n=i[9]-i[8]+i[7]-i[6]-i[5]+i[4]-i[3];
printf("%d ",c[i[9]]-c[i[8]]+c[i[7]]-c[i[6]]-c[i[5]]+c[i[4]]-c[i[3]]);
printf("%d ",i[9]-i[8]+i[7]-i[6]-i[5]+i[4]-i[3]);
if(n!=0)
printf("%f \n",m/n);
else
printf("\n");
m=c[i[10]]-c[i[9]]+c[i[8]]-c[i[7]]-c[i[6]]+c[i[5]]-c[i[4]],n=i[10]-i[9]+i[8]-i[7]-i[6]+i[5]-i[4];
printf("%d ",c[i[10]]-c[i[9]]+c[i[8]]-c[i[7]]-c[i[6]]+c[i[5]]-c[i[4]]);
printf("%d ",i[10]-i[9]+i[8]-i[7]-i[6]+i[5]-i[4]);
if(n!=0)
printf("%f \n",m/n);
else
printf("\n");
m=c[i[11]]-c[i[10]]+c[i[9]]-c[i[8]]-c[i[7]]+c[i[6]]-c[i[5]],n=i[11]-i[10]+i[9]-i[8]-i[7]+i[6]-i[5];
printf("%d ",c[i[11]]-c[i[10]]+c[i[9]]-c[i[8]]-c[i[7]]+c[i[6]]-c[i[5]]);
printf("%d ",i[11]-i[10]+i[9]-i[8]-i[7]+i[6]-i[5]);
if(n!=0)
printf("%f \n",m/n);
else
printf("\n");
m=c[i[12]]-c[i[11]]+c[i[10]]-c[i[9]]-c[i[8]]+c[i[7]]-c[i[6]],n=i[12]-i[11]+i[10]-i[9]-i[8]+i[7]-i[6];
printf("%d ",c[i[12]]-c[i[11]]+c[i[10]]-c[i[9]]-c[i[8]]+c[i[7]]-c[i[6]]);
printf("%d ",i[12]-i[11]+i[10]-i[9]-i[8]+i[7]-i[6]);
if(n!=0)
printf("%f \n",m/n);
else
printf("\n");
}
[此贴子已经被作者于2016-12-26 11:33编辑过]