2 Find Roots Using Bisection Method Q37188587

Write C code to

2. Find all the roots using the bisection method

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 Process exited after 0.07887 seconds with return value 0 Press any key to continue . - .

root0.619057

OR
OR

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.