الگوريتم روش تنصيف در محاسبه ريشه (درس محاسبات عددي)
#include<iostream.h>
#include<math.h>
#include<conio.h>
double f(double x){return 3*x-exp(-x);}
void main(){
float a,b,eps,x;
int n=1;
clrscr();
cout<<"enter a,b,eps:";
cin>>a>>b>>eps;
x=(a+b)/2;
while(fabs(f(x))>=eps){
if (f(x)*f(a)>0)
a=x;
else
b=x;
x=(a+b)/2;
n++;
}
cout<<"ROOT = "<<x;
cout<<"\nITERATION = "<<n;
getch();
}