#include <stdio.h>
#include<math.h>
float
value(
float
x)
{
float
f;
f=
pow
(x,5)-3*(
pow
(x,2))-100;
return
f;
}
float
value1(
float
y)
{
float
f;
f=5*(
pow
(y,4))-(6*y);
return
f;
}
float
fun(
float
y,
float
x)
{
float
p;
p=x-(value(y)/value1(y));
return
p;
}
int
main()
{
int
i,n;
float
p[20],a,b;
printf
(
"\nQuestion is : x^2-5x+6 =0 \n"
);
printf
(
"\nEnter how many iteration : "
);
scanf
(
"%d"
,&n);
for
(i=0;i<n;i++)
{
p[i]=value(i);
printf
(
"\n f[%d] : %f "
,i,p[i]);
}
for
(i=0;i<n;i++)
{
if
(p[i]*p[i+1]<0)
{
a=i;
b=i+1;
printf
(
"\n\nThe root lies between: [%2.4f %2.4f]"
,a,b);
break
;
}
}
p[0]=3.5;
printf
(
"\n\n f[0] : %f "
,p[0]);
for
(i=1;i<n;i++)
{
p[i]=fun(p[i-1],p[i-1]);
printf
(
"\n f[%d] : %f "
,i,p[i]);
}
return
0;
}
By - milan zinzuvadiya
No comments:
Post a Comment