搞个程序也没算出等于100的,程序不完整,少了括划功能。
但还能算,要把100改成88或120等,都有答案,就没有100.
main()
{
int x=8,y,j,n=1;
int i1=0,i2=0,i3=0,i4=0,i5=0,i6=0,i7=0;
int y1,y2,y3,y4,y5,y6,y7;
char ch[4]="+-*/";
while(i1<4)
{
switch(i1)
{
case 0:x+=8;break;
case 1:x-=8;break;
case 2:x*=8;break;
case 3:x/=8;break;
}
y1=x;
i1++;
while(i2<4)
{
switch(i2)
{
case 0:x+=8;break;
case 1:x-=8;break;
case 2:x*=8;break;
case 3:x/=8;break;
}
y2=x;
i2++;
while(i3<4)
{
switch(i3)
{
case 0:x+=8;break;
case 1:x-=8;break;
case 2:x*=8;break;
case 3:x/=8;break;
}
y3=x;
i3++;
while(i4<4)
{
switch(i4)
{
case 0:x+=8;break;
case 1:x-=8;break;
case 2:x*=8;break;
case 3:x/=8;break;
}
y4=x;
i4++;
while(i5<4)
{
switch(i5)
{
case 0:x+=8;break;
case 1:x-=8;break;
case 2:x*=8;break;
case 3:x/=8;break;
}
y5=x;
i5++;
while(i6<4)
{
switch(i6)
{
case 0:x+=8;break;
case 1:x-=8;break;
case 2:x*=8;break;
case 3:x-=8;break;
}
i6++;
y6=x;
while(i7<4)
{
switch(i7)
{
case 0:x+=8;break;
case 1:x-=8;break;
case 2:x*=8;break;
case 3:x/=8;break;
}
i7++;
if(x==88)
/*在这改值,先用假如等于88就显示出算法,改100没结果。*/
goto log1;
else
x=y6;
}
x=y5;
i7=0;
}
x=y4;
i6=0;
}
x=y3;
i5=0;
}
x=y2;
i4=0;
}
x=y1;
i3=0;
}
i2=0;
}
log1:
printf("8%c8%c8%c8%c8%c8%c8%c8=100\n",ch[i1-1],ch[i2-1],ch[i3-1],ch[i4-1],ch[i5-1],ch[i6-1],ch[i7-1]);
}