#include<stdio.h>
#include<conio.h>
#include<math.h>
main()
{
float a,x1,x2;
int i;
float func(float);
float func1(float);
clrscr();
printf("\n enter the initial value");
scanf("%f",&a);
x1=a;
printf("a=%f",x1);
x2=(x1-(func(x1)/func1(x1)));
printf("\nx2=%f",x2);
for(i=1;x1!=x2;i++)
{
printf("\n(%d)%f",i,x2);
x1=x2;
x2=x1-(func(x1)/func1(x1));
}
printf("\n the root is %f converge is %d approximately",x2,i);
getch();
return(0);
}
float func(float x)
{
return(pow(x,3)+(-2*x-5));
}
float func1(float x)
{
return((3*pow(x,2)-2));
}
#include<conio.h>
#include<math.h>
main()
{
float a,x1,x2;
int i;
float func(float);
float func1(float);
clrscr();
printf("\n enter the initial value");
scanf("%f",&a);
x1=a;
printf("a=%f",x1);
x2=(x1-(func(x1)/func1(x1)));
printf("\nx2=%f",x2);
for(i=1;x1!=x2;i++)
{
printf("\n(%d)%f",i,x2);
x1=x2;
x2=x1-(func(x1)/func1(x1));
}
printf("\n the root is %f converge is %d approximately",x2,i);
getch();
return(0);
}
float func(float x)
{
return(pow(x,3)+(-2*x-5));
}
float func1(float x)
{
return((3*pow(x,2)-2));
}
write the output also
ReplyDelete