#include<iostream>
#include<cmath>
#define EPS .00001
using namespace std;
bool equal(double y,double val)
{
if(abs(y-val)<EPS)
return true;
else
return false;
}
double bisection(double l,double u,double val)
{
double mid=(l+u)/2;
double y=mid*mid;
bool isequal=equal(y,val);
if(isequal)
return mid;
else if(y>val)
return bisection(l,mid,val);
else
return bisection(mid,u,val);
}
int main()
{
double b;
cin>>b;
cout<<"square root of "<<b<<" by bisection method : "<<bisection(0,50,b)<<endl;
}
#include<cmath>
#define EPS .00001
using namespace std;
bool equal(double y,double val)
{
if(abs(y-val)<EPS)
return true;
else
return false;
}
double bisection(double l,double u,double val)
{
double mid=(l+u)/2;
double y=mid*mid;
bool isequal=equal(y,val);
if(isequal)
return mid;
else if(y>val)
return bisection(l,mid,val);
else
return bisection(mid,u,val);
}
int main()
{
double b;
cin>>b;
cout<<"square root of "<<b<<" by bisection method : "<<bisection(0,50,b)<<endl;
}
কোন মন্তব্য নেই:
একটি মন্তব্য পোস্ট করুন