| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛

问题点数：0 回复次数：9

DO IT YOURSELF !

```#include <stdio.h>

char reversion(char signal) {
if (signal == '*') {
return '/';
} else if (signal == '/') {
return '*';
} else if (signal == '+') {
return '-';
} else if (signal == '-') {
return '+';
}
}

void get_equation(int A, int B, int C, int D, char x, char y, char z, char w, char* equ) {
x = reversion(x);
y = reversion(y);
z = reversion(z);
w = reversion(w);
sprintf(equ,"a=%d%c(%d%c(%d%c(%d%ca)))",D,w,B,z,C,y,A,x);
}

float solve(int step) {
float temp;
for (float x = -9; x < 9*step; x++) {
float ttemp;
ttemp = (8*step-(5*step+(9*x/21)) - x);
if (ttemp == 0) {
return x/step;
}
if (x > 1 && (ttemp * temp < 0)) {
break;
}
temp = ttemp;
}
solve(step*10);
}

float cal(float x, char opr, float y) {
if (opr == '*') {
return x*y;
} else if (opr == '/') {
return x/y;
} else if (opr == '+') {
return x+y;
} else if (opr == '-') {
return x-y;
}
}

int main() {
char equ[100] = {0};
char x = '*';
char y = '*';
char z = '+';
char w = '-';
int A = 21;
int B = 5;
int C = 9;
int D = 8;
float a, b, c, d;
get_equation(A, B, C, D, x, y, z, w, equ);
printf("%s\n",equ);
a = solve(1);
b = cal(A, reversion(x), a);
d = cal(C, reversion(y), b);
c = cal(B, reversion(z), d);
printf("a=%f\n", a);
printf("b=%f\n", b);
printf("c=%f\n", c);
printf("d=%f\n", d);
return 0;
}```

• 10
• 1/1页
• 1