/******************************************************************************
Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby,
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.
*******************************************************************************/
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;
float f(float x){
return x*x-6*x+5;
}
int main(){
int nr=0;
float x,a=2,b=12345,m,epsi=0.0001;
if(fabs(f(a))<epsi) cout<<a<<endl;
else if(fabs(f(b))<epsi) cout<<b<<endl;
else {
m=(a+b)/2;
while(fabs(f(m))>epsi){
if(f(a)*f(m)>0) a=m;
else b=m;
m=(a+b)/2;
nr++;
}
}
cout<<"radacina = "<<m<<endl;
cout<<"(cu eroarea "<<f(m)<<")"<<endl;
cout<<"in "<<nr<<" pasi"<<endl;
return 0;
}