运行时出现floating point error domain 跪求解决方法

来源:百度知道 编辑:UC知道 时间:2024/05/29 10:47:55
这是一个求四个一位数,是否可以运算出24的小程序,本人是初学者,请问各位高手,这个程序错在哪啊?
#include<math.h>
float num[100][6],k,l=0;
int j=-1;
void tnm(float x,float y)
{j++;
num[j][0]=x+y;
num[j][1]=x-y;
num[j][2]=y-x;
num[j][3]=x*y;
y!=0?num[j][4]=x/y:x*y;
x!=0?num[j][5]=y/x:x*y;
}
float tpnm(float w,float x,float y,float z)
{int a=0,b=0,c=0,d;
j=0;
tnm(w,x);
tnm(y,z);
d=j;
for (;a<6;a++)
{while (b<=5)
{tnm(num[d][a],num[d-1][b]);
do {k=num[j][c];
if (k==24) break;
else c++;
}
while (c<6);
if (k==24) break;
else {b++;
c=0;}
}
if (k==24) break;
else c=0;
}
if (k==24) return(1);
else return(0);
}
float thpnm(float w,float x,float y,float z)
{int e,f=0,g,h=0,i=0;
j=0;
tnm(w,x);
e=f;
for (;f<6;f++)
{tnm(num[e][f],y);

换一下算法.枚举运算,对输入的四个数a,b,c,d执行下面54种运算.如果有某一个得数是24即可以算出否则不能.
a+b+c+d
a+b+c-d
a+b-c-d
a*b+c+d
a*b*c+d
a*b+c*d
a*b*c*d
a/b+c+d
a/b/c+d
a/b+c/d
a*b*c/d
a*b/c/d
a*b/c+d
a/b+c*d
a*b-c-d
a*b*c-d
a*b-c*d
a*b/c-d
a*b+c-d
(a+b+c)*d
(a+b-c)*d
(a*b+c)*d
(a*b-c)*d
(a/b+c)*d
(a/b-c)*d
(a-b/c)*d
(a+b+c)/d
(a+b-c)/d
(a*b+c)/d
(a*b-c)/d
(a/b+c)/d
(a+b)*c+d
(a-b)*c+d
(a+b)/c+d
(a-b)/c+d
(a+b)*c-d
(a-b)*c-d
(a+b)/c-d
(a+b)*c*d
(a-b)*c*d
(a+b)/c*d
(a-b)/c*d
(a+b)/c/d
(a+b)*(c+d)
(a+b)*(c-d)
(a-b)*(c-d)
(a+b)/(c+d)
(a+b)/(c-d)
a/b+c-d
a+b/(c+d)
a*b/(c+d)
a+b/(c-d)
a*b/(c-d)
a/(b-c/d)