-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoba.c
54 lines (46 loc) · 897 Bytes
/
coba.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include<stdio.h>
//function used is x^3-2x^2+3
double func(double x)
{
return x*x*x - 2*x*x + 3;
}
double e=0.01;
double c;
void bisection(double a,double b)
{
if(func(a) * func(b) >= 0)
{
printf("Incorrect a and b");
return;
}
c = a;
while ((b-a) >= e)
{
c = (a+b)/2;
if (func(c) == 0.0){
printf("Root = %lf\n",c);
break;
}
else if (func(c)*func(a) < 0){
printf("Root = %lf\n",c);
b = c;
}
else{
printf("Root = %lf\n",c);
a = c;
}
}
}
int main()
{
double a,b;
a=-10;
b=20;
printf("The function used is x^3-2x^2+3\n");
printf("a = %lf\n",a);
printf("b = %lf\n",b);
bisection(a,b);
printf("\n");
printf("Accurate Root calculated is = %lf\n",c);
return 0;
}