See - we have the equation y(x) = 0 . It is necessary to define this function.
double y(double x) { // Тело напишите сами }
We have a segment on which we are looking. So? So there is
double a,b;
(don't forget to initialize!). Next, we need to know the signs of the function values at these points:
double ya = y(a), yb = y(b);
It would be nice to check that they have different signs ...
Further we will work in a cycle, narrowing the segment. Those. until we get |ab| < eps |ab| < eps , or since we always have b > a , just ba < eps . Those.
while(b - a > eps) {
And what is there? Delhi in half:
double x = (a + b)/2;
and find the value of the function:
double f = y(x);
Now let's see ... if it is of the same sign as a , we move a , if b is, respectively.
if (ya * f >= 0) a = x; else b = x;
This cycle ends ...
And now collect all this in a heap, add what is missing, achieve that it is compiled, debug it (I could have missed a mistake ... :)) and carry it.
PS You did not really hope to get a finished job? :)