Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
628 B
1
Indexable
Never
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
float f(float x){
	return(x*x*x-4*x-9);
}
float df(float x){
	return(3*x*2-4);
}
int main(){
	float xo,aerr,x;
	int flag=0;
	printf("Enter the value of xo : ");
	scanf("%f",&xo);
	printf("Enter the value of allowed Error : ");
	scanf("%f",&aerr);
	int itr=0;
	do{
		itr++;
		x= xo-f(xo)/df(xo);
		printf("\n %d Iteration, value of x[%d] is =%f, value of f(x)=%f",itr,itr,x,f(x));
		if(fabs(x-xo)<=aerr){
			printf("\n The root of the Equation is %f after %d iterations",x,itr);
			flag=1;
		}
		else{
		xo=x;
		}	
	}while(flag==0);
	return 0;
}
Leave a Comment