Anda di halaman 1dari 1

#include<stdio.

h>
#include<stdlib.h>
#include<conio.h>
#include<math.h>
#include<string.h>
#include<process.h>
#include<iostream.h>

float f(float x)
{
return pow(x,3.0)-(2*(x*x))-(3.0*x)-(8);
}
int main()
{
float a,b,c,d,e;
int count=0,n;

cout<<"Masukkan Nilai x0 = ";


cin>>a;
cout<<"Masukkan Nilai x1 = ";
cin>>b;
cout<<"Masukkan Batas Iterasi = ";
cin>>n;
e = 0.00001;
printf("x0 = %f\n",a);
printf("x1 = %f\n",b);
do
{
if(f(a)==f(b))
{
printf("\nNilai a dan b sama , solusi tidak dapat ditemukan.\n");
return 0;
}
c=(a*f(b)-b*f(a))/(f(b)-f(a));
a=b;
b=c;
printf("X%d = %f | error : %.10f\n",count+2,c,fabs(f(c)));
count++;
if(count==n)
{
break;
}
getch();
}
while(fabs(f(c))>e);
printf("\n Solusi yang dibutuhkan adalah %f\n",c);
return 0;

getch();
}