C code Bisection Method

Q&ACategory: MathematicsC code Bisection Method
Arko GoswamiArko Goswami asked 2 years ago

please correct the code..

/* User Inputs are - Lower Limit , Upper Limit , Last Digit of Roll Number*/
/*Bisection Method*/
#include<stdio.h>
#include<math.h>
float fnc(float x,int n)
{
float a=1+(n+1)/20;
return exp(asin(x))+sinh(x)-a*(1+x*x);
}
int main()
{
float a,b,e,y;
int m,i=1;
float fnc(float x,int n);
printf("Enter the Lower limit : ");
scanf("%f",&a);
printf("Enter the Upper limit : ");
scanf("%f",&b);
printf("Enter the last digit of your Roll Number : ");
scanf("%f",&m);
if(fnc(a,m)*fnc(b,m)>0.0)
{
printf("There is no root");
}
else
{
do
{
y=(a+b)/2.0;
printf("\n Iteration %d : Approximation= %f",i,y);
i++;
if(fnc(y,m)*fnc(b,m)<0)
{
a=y;
}
else if(fnc(b,m)*fnc(y,m)>0)
{
b=y;
}
else
{
break;
}

}while(fabs(fnc(y,m))>0.00001);
printf("\n \n The root is %f",y);
}

}
 

Your Answer

18 + 17 =