#include <stdio.h>
#include <math.h>

double f (double); /* f的原型，函数定义可以写在任何地方 */

double crossp (double x1, double x2) {
    double y1 = f(x1), y2 = f(x2);
    return (x1 * y2 - x2 * y1) / (y2 - y1);
}

double root (double x1, double x2) {
    double x, y, y1 = f(x1);

    do {
        x = crossp(x1, x2);
        y = f(x);
        if (y * y1 > 0) { /* y与y1符号相同，新区间为 [x,x2] */
            x1 = x; y1 = y;
        }
        else x2 = x;      /* y与y1符号不同，新区间为 [x1,x] */
    } while (fabs(y) >= 1E-6); /* y值不够小，继续 */

    return x;
}

double f (double x) {
    return x * sin(x) - 2 * x * x;
}

int main () {    /* 定义从略 */  }


