int solve_equation (list < double > & p, vector < double > & x) { if (p.size () == 0) // 0 = 0 return - 1; if (eq (p.front (), 0)) // a = 0 { p.pop_front (); return solve_equation (p, x); } if (p.size () == 1) return 0; if (eq (p.back (), 0)) // pn = 0 { p.pop_back (); int flag = solve_equation (p, x); p.push_back (0.000); int i; forn (i, x.size ()) if (eq (x[i], 0.000)) return 1; else if (x[i] > 0) break; x.insert (x.begin () + i, 0.000); return 1; }
// Runs an internal set of tests void run_tests() { int answer = 0; char tmp[66]; char *ptr; ptr = tmp; int runs = 0; while(runs < 1000) { char equation[256]; int answer = generate_one_equation(equation); printf("r: @d @s = @d\n", runs, equation, answer); runs++; } for (int i = 0; i < TEST_LEN; i++) { solve_equation(tests[i], &answer); printf("equation: @s = @d \n", tests[i], answer); printf((answer == answers[i]) ? "correct\n" : "wrong\n"); printf("-----------------\n"); } }
int main() { double a, b, c; a = get_value(); b = get_value(); c = get_value(); solve_equation(a, b, c); }