Source code Algoritma Biseksi c++



#include<iostream>
#include<math.h>
using namespace std;

double f(double x)
{
 double y;
 y=x*x-5*x-6;
 return(y);
}

   int main()
{
 float a,b,c,toleransi;
 int i;

 cout<<"masukkan batas atas (a)= ";
 cin>>a;
 cout<<"masukkan batas bawah (b)= ";
 cin>>b;
 cout<<"masukkan batas toleransi= ";
 cin>>toleransi;

 i=0;
 cout<<"\n";
 cout<<"Iterasi \t a \t b \t";
 cout<<"\n";
 if(f(a)*f(b)<0)
 {
  c=(a+b)/2;
 
  while( fabs(f(c))>toleransi)
  {
   i=i+1;
   if(f(a)*f(c)<0)
    b=c;
   else
    a=c;
 
  c=(a+b)/2;

 cout<<"\n";

 cout<<"\n";
 cout<<i <<"\t";
 cout<<a <<"\t";
 cout<<b <<"\t";
 cout<<c <<"\t";
 cout<<"\t f(c)= "<<f(c)<<"\n\n";
  }
 cout<<"akarnya = "<<c<<"\n";
 
 }
 else
 cout<<"tidak ada akar"<<"\n";
}

0 Response to "Source code Algoritma Biseksi c++"

Post a Comment