#include<stdlib.h>
#include<math.h>
float function(float x)
{
return (exp(x)+x);
}
void main()
{
float a,b,c;
printf("Enter a and b : ");
scanf("%f%f",&a,&b);
if(function(a)*function(b)>0)
{
printf("Enter appropriate interval\n");
exit(0);
}
else
{
do
{
c=(a+b)/2;
if(function(a)*function(c)<0)
{
b=c;
}
else
{
a=c;
}
}while(fabs(function(c))>0.0005);
printf("solution = %f \t\tf(x)= %f",c,function(c));
}
}
0 comments:
Post a Comment