Write C code to
2. Find all the roots using the bisection method Show transcribed image text 2. Find all the roots using the bisection method
Answer
#include<stdio.h>
#include<math.h>
float func (float x)
{
return exp(x) – (3 * x);
}
int main ()
{
float x, x1, a = 0, b = 2;
float error = 0.00001;
x = (a + b) / 2;
while(true)
{
if (func(a)*func(x) < 0)
b=x;
else
a=x;
x1 = (a + b) / 2;
if (fabs(x1-x) < error)
{
break;
return 0;
}
x=x1;
}
printf(“root = %fn”, x1);
return 0;
}
root0.619057
OR
OR