-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBisection Method.cpp
More file actions
50 lines (47 loc) · 832 Bytes
/
Copy pathBisection Method.cpp
File metadata and controls
50 lines (47 loc) · 832 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
50
/*
Created By : Nazmus Sakib
*/
#include<bits/stdc++.h>
using namespace std;
double solve(double x)
{
return (x*x*x+3*x-5);
}
void bisec(double a, double b,int n)
{
if(solve(a)*solve(b)>=0)
{
cout<<"Guess values are incorrect"<<endl;
return;
}
else
{
double c;
for(int i=0; i<n; i++)
{
c=(a+b)/2;
if(solve(c)==0.0)
break;
else if(solve(c)*solve(a)<0)
{
b=c;
}
else
{
a=c;
}
}
cout<<"Root value is: "<<c<<endl;
}
}
int main()
{
cout<<"Enter two values: "<<endl;
double a,b;
int n;
cin>>a>>b;
cout<<"Enter number of iteration: "<<endl;
cin>>n;
bisec(a,b,n);
return 0;
}