谁能用3 7 8 9加减乘除使结果等于24
来源:学生作业帮助网 编辑:作业帮 时间:2024/11/16 11:38:03
谁能用3 7 8 9加减乘除使结果等于24
谁能用3 7 8 9加减乘除使结果等于24
谁能用3 7 8 9加减乘除使结果等于24
请输入四个数:
3 7 8 9
请输入计算值:
24
满足条件的有:
3*(7-8+9)=24
3*((7-8)+9)=24
3*(7-(8-9))=24
3*(7+9-8)=24
3*((7+9)-8)=24
3*(7+(9-8))=24
3*(9+7-8)=24
3*((9+7)-8)=24
3*(9+(7-8))=24
3*(9-8+7)=24
3*((9-8)+7)=24
3*(9-(8-7))=24
(7-8+9)*3=24
((7-8)+9)*3=24
(7-(8-9))*3=24
(7+9-8)*3=24
((7+9)-8)*3=24
(7+(9-8))*3=24
(9+7-8)*3=24
((9+7)-8)*3=24
(9+(7-8))*3=24
(9-8+7)*3=24
((9-8)+7)*3=24
(9-(8-7))*3=24
总共24个解!
Continue(y/n)?
C语言计算24点程序:
#include
#include
#include
#include
#include
double fun1();
double fun2();
double fun3();
double fun4();
char calc[64];
int n;
double fun1()
{
double t;
t=fun2();
while((calc[n]=='+')||(calc[n]=='-'))
{
switch(calc[n])
{
case '+':n++,t=t+fun2();break;
case '-':n++,t=t-fun2();break;
}
}
return(t);
}
double fun2()
{
double t;
t=fun3();
while((calc[n]=='*')||(calc[n]=='/'))
{
switch(calc[n])
{
case '*':n++,t=t*fun3();break;
case '/':n++,t=t/fun3();break;
}
}
return(t);
}
double fun3()
{
char num[16];
int i=0;
double t=0;
if(calc[n]=='(')
{
n++,t=fun1(),n++;
}
else if(fun4())
{
while(fun4())
{
num[i++]=calc[n++];
}
num[i]='\0';
t=atof(num);
}
return(t);
}
double fun4()
{
if(((calc[n]>='0'&&calc[n]0&&(calc[n-1]=='+'||calc[n-1]
=='-'||calc[n-1]=='*'||calc[n-1]=='/'||calc[n-1]=='^'||calc[n-1]=='(')))
return(1);
else
return(0);
}
int main(void)
{
int i,j,k,w,x,y,z,f,g,flag;
char sym[4]="+-*/",exp[24][32];
float a,b,c,d,e,num[5];
loop:
printf("请输入四个数:\n");
scanf("%f %f %f %f",&a,&b,&c,&d);
printf("\n请输入计算值:\n");
scanf("%f",&e);
printf("\n满足条件的有:\n");
f=g=0,flag=0,num[0]=a,num[1]=b,num[2]=c,num[3]=d;
for(w=0;w
3*[(9+7)-8]=24
1: 3 × (7 - 8 + 9)
2: 3 × ((7 - 8) + 9)
3: 3 × (7 - (8 - 9))
4: 3 × (7 + 9 - 8)
5: 3 × ((7 + 9) - 8)
6: 3 × (7 + (9 - 8))
7: 3 × (9 + 7 - 8)
8: 3 × ((9 + 7) - 8)
全部展开
1: 3 × (7 - 8 + 9)
2: 3 × ((7 - 8) + 9)
3: 3 × (7 - (8 - 9))
4: 3 × (7 + 9 - 8)
5: 3 × ((7 + 9) - 8)
6: 3 × (7 + (9 - 8))
7: 3 × (9 + 7 - 8)
8: 3 × ((9 + 7) - 8)
9: 3 × (9 + (7 - 8))
10: 3 × (9 - 8 + 7)
11: 3 × ((9 - 8) + 7)
12: 3 × (9 - (8 - 7))
13: (7 - 8 + 9) × 3
14: ((7 - 8) + 9) × 3
15: (7 - (8 - 9)) × 3
16: (7 + 9 - 8) × 3
17: ((7 + 9) - 8) × 3
18: (7 + (9 - 8)) × 3
19: (9 + 7 - 8) × 3
20: ((9 + 7) - 8) × 3
21: (9 + (7 - 8)) × 3
22: (9 - 8 + 7) × 3
23: ((9 - 8) + 7) × 3
24: (9 - (8 - 7)) × 3
收起