Math problem in primary school a 1 ... 9=100

Source: Internet
Author: User

1 2 3 4 5 6 7 8 9=100 fill in +=*/so the result =100 without parentheses

There seems to be no particularly good general solution, programming poor to lift a bit

int algorithm_100 ()
{
int i,j,n,nret=0;
float Fnum[32],fres;
TCHAR szoperate[]= "+-x/", szoper[10]={0},sztext[256]={0};
for (i=0; i<65536; i++)//8 operators, 4 possible, 8 4-square =65536
{
n = 0;
Fnum[0] = 1;
for (j=0; j<8; j + +)
{
SZOPER[J] = szoperate[(i>> (j*2)) &3];
if (szoper[j] = = ' x ')
{
Fnum[n] *= (j+2);
} else if (szoper[j] = = '/')///
{
Fnum[n]/= (j+2);
} else//+-
{
Fnum[++n] = Szoper[j];
Fnum[++n] = j+2;
}
}
Fres = fnum[0];
CAC Result
for (j=1; j<n; j+=2)
{
if (fnum[j] = = ' + ')//+
Fres + = fnum[j+1];
Else
Fres-= fnum[j+1];
}
if (fres = = 100)
{
for (j=0; j<9; j + +)
{
Sztext[j*2+0] = ' 1 ' +j;
SZTEXT[J*2+1] = Szoper[j];
}
TRACE (Sztext);//output result
nret++;
}
}
return nret;
}

The results are as follows:

1x2x3x4+5+6+7x8+9
1-2+3x4x5+6x7+8-9
1-2+3x4x5-6+7x8-9
1+2+3+4+5+6+7+8x9 one of the most easily thought-out
1x2x3+4+5+6+7+8x9
1-2x3+4x5+6+7+8x9
1+2x3+4x5-6+7+8x9
1-2x3-4+5x6+7+8x9
1+2-3x4+5x6+7+8x9
1+2x3x4x5/6+7+8x9
1x2x3x4+5+6-7+8x9
1-2x3-4-5+6x7+8x9
1+2-3x4-5+6x7+8x9
1+2+3-4x5+6x7+8x9
1x2x3-4x5+6x7+8x9

Math problem in primary school a 1 ... 9=100

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.