-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathBisection method (NMCT).cpp
More file actions
49 lines (47 loc) · 868 Bytes
/
Bisection method (NMCT).cpp
File metadata and controls
49 lines (47 loc) · 868 Bytes
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
//write the program bisection method equation solved
//SUMIT KUMAR
#include<stdio.h>
#include<math.h>
#define ERR 0.01
double func(double x)
{
//Equation is 2-x^2.
//put the Equation
return(2-x*x);
}
void bisection(double a,double b)
{
int i=0;
if(func(a)*func(b)>=0.0)
{
printf("VALUSE ARE OF WORNG A AND B : \n");
return;
}
double c=a;
while((b-a)>=ERR)
{
i++;
c=(a+b)/2;
if(func(c)==0.0)
{
break;
}
else if(func(a)*func(c)<0.0)
{
b=c;
}
else
a=c;
printf("NUMBER OF ITERATION: %d VALUE OF C %f\n",i,c);
}
printf("ROOT :- %lf \n",c);
printf("NUMBER OF ITERATION : %d",i);
return;
}
int main()
{
// a and b is question put the value.
double a=0, b=2;
bisection(a,b);
return 0;
}