Untitled
unknown
plain_text
2 years ago
918 B
7
Indexable
//REGULA FALSI
#include<stdio.h>
#include<math.h>
float f(float x){
return(x*x*x-4*x-9);
}
int main(){
float a,b,x,aerr;
int itr=0,flag=0;
do{
printf("\nEnter the two values for interval: ");
scanf("%f%f",&a,&b);
if(f(a)*f(b)<0){
printf("\n The root of the equation lies between %.2f and %.2f",a,b);
flag=1;
}
else
printf("\n Wrong Intervals!!!");
}while(flag==0);
printf("\n Enter the allowed error");
scanf("%f",&aerr);
do{
itr++;
x=(a*f(b)-b*f(a))/(f(b)-f(a));
printf("\n%d Iteration, value of X[%d] is=%f,value of f(x)=%f",itr,itr,x,f(x));
if(fabs(f(x))<=aerr){
printf("\n the root of the equation is %f after %d iteration",x,itr);
flag=0;
}
else if(f(a)*f(x)<0)
b=x;
else
a=x;
}while (flag==1);
return 0;
}Editor is loading...
Leave a Comment