You are on page 1of 1

#include<stdio.

h>
#include<stdlib.h>
#include<math.h>
int main(){
int k;
float a, b, x, y, e, ya, yb, yx; // a variavel "e" a preciso, as variaveis ya
, yb, e yx so, respectivamente, f(a), f(b) e f(x)
printf("Digite os valores do intervalo [a,b]\n");
scanf("%f %f", &a, &b); //recebe valores iniciais de a e b
printf("\n\nDigite o valor da precisao\n");
scanf("%f", &e); //recebe valor da preciso e
printf("\n
a
b
f(a)
f(b)
x
f(x)
");
for(k=1; k=9999; k++){ //numero maximo de iteraes 9999
printf("\n\n%f %f ",a, b);
x=a;
y=5*pow(x,3)-2*pow(x,2)+8*x-10;
printf("%f ", y);
ya=y;
x=b;
y=5*pow(x,3)-2*pow(x,2)+8*x-10;
printf("%f ", y);
yb=y;
x=((a*yb)-(b*ya))/(yb-ya);
printf("%f ", x);
y=5*pow(x,3)-2*pow(x,2)+8*x-10;
yx=y;
printf("%f", yx);
if (ya>0&&yx>0||ya<0&&yx<0)
a=x;
else b=x;
if (fabs(yx)<e||fabs((a-b))<e) break; //condio de parada
}
printf("\n\nx = %f, com uma precisao de %f\n\n", x, e);
system("pause");
}

You might also like