刚刚学C语言,做了第一题,大侠看看有什么值得改进的地方。
#define NUM 10
main()
{int a,b,c,d,e,f,g,x,y,z,i1,i2,i3,i4,i5,i6,i7,i8,j,inde[NUM];
clrscr();
for(i1=1;i1<9;i1++)
{for(j=0;j<=9;j++) {inde[j]=1;}
/* printf("%2d%2d%2d%2d%2d%2d%2d%2d%2d%2d",inde[0],inde[1],inde[2],inde[3],inde[4],inde[5],inde[6],inde[7],inde[8],inde[9]); */
a=i1;x=i1+1;
inde[i1]=0;inde[i1+1]=0;
for(i2=0;i2<=9;i2++)
{if(inde[i2]) {b=i2;inde[i2]=0;}
else continue;
for(i3=0;i3<=9;i3++)
{if(inde[i3]) {c=i3;inde[i3]=0;}
else continue;
for(i4=0;i4<=9;i4++)
{if(inde[i4]) {d=i4;inde[i4]=0;}
else continue;
for(i5=0;i5<=9;i5++)
{if(inde[i5]) {e=i5;inde[i5]=0;}
else continue;
for(i6=0;i6<=9;i6++)
{if(inde[i6]) {f=i6;inde[i6]=0;}
else continue;
for(i7=0;i7<=9;i7++)
{if(inde[i7]) {g=i7;inde[i7]=0;}
else continue;
for(i8=0;i8<=9;i8++)
{if(inde[i8])
{y=i8;inde[i8]=0;
z=1+2+3+4+5+6+7+8+9-a-b-c-d-e-f-g-x-y;
if((a*10000+b*1000+c*100+d*10+e+2*(d*100+f*10+g)) == (x*10000+y*1000+z*100+d*10+e))
{printf(" A B C D E\n");
printf(" D F G\n");
printf(" + D F G\n");
printf("-----------\n");
printf(" X Y Z D E\n");
printf("\n");
printf("%2d%2d%2d%2d%2d\n",a,b,c,d,e);
printf(" %2d%2d%2d\n",d,f,g);
printf(" + %2d%2d%2d\n",d,f,g);
printf("-----------\n");
printf("%2d%2d%2d%2d%2d\n",x,y,z,d,e);
printf("\n");
printf("a =%2d,b =%2d,c =%2d,d =%2d,e =%2d,f =%2d,g =%2d,x =%2d,y =%2d,z =%2d\n",a,b,c,d,e,f,g,x,y,z);
getch();
}
}
else continue;
inde[i8]=1;
}
inde[i7]=1;
}
inde[i6]=1;
}
inde[i5]=1;
}
inde[i4]=1;
}
inde[i3]=1;
}
inde[i2]=1;
}
inde[i1]=1;
}
}