#include<stdio.h>
#include<conio.h>
#include<math.h>
float F(float x)
{
return(x*x*x-(5*x)+1);
}
void main()
{
int i=0;
float a,b,c,err,temp;
clrscr();
printf("enter permissive error\n");
scanf("%f",&err);
do
{
printf("enter value of a & b\n");
scanf("%f%f",&a,&b);
}
while(F(a)*F(b)>0);
c=0;
do
{
temp=c;
c=(a*F(b)-b*F(a))/(F(b)-F(a));
if(F(a)*F(b)<0)
{
b=c;
}
else
{
a=c;
}
i++;
printf("iteration %d:",i);
printf("%f\n",c);
}
while(fabs(temp-c)>err);
printf("root of equation is %f",c);
getch();
}
#include<conio.h>
#include<math.h>
float F(float x)
{
return(x*x*x-(5*x)+1);
}
void main()
{
int i=0;
float a,b,c,err,temp;
clrscr();
printf("enter permissive error\n");
scanf("%f",&err);
do
{
printf("enter value of a & b\n");
scanf("%f%f",&a,&b);
}
while(F(a)*F(b)>0);
c=0;
do
{
temp=c;
c=(a*F(b)-b*F(a))/(F(b)-F(a));
if(F(a)*F(b)<0)
{
b=c;
}
else
{
a=c;
}
i++;
printf("iteration %d:",i);
printf("%f\n",c);
}
while(fabs(temp-c)>err);
printf("root of equation is %f",c);
getch();
}
No comments:
Post a Comment