-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfunc6.c
More file actions
52 lines (51 loc) · 650 Bytes
/
Copy pathfunc6.c
File metadata and controls
52 lines (51 loc) · 650 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#define f(x) ((x*x*x)-18)
int main()
{
float a=0,b=0,error=0,c,d;
int i=0;
printf("input interval");
scanf("%f%f",&a,&b);
if((f(a)*f(b)>0)
{
printf("invalid interval");
}
else if(f(a)==0||f(b)==0)
{
printf("root is %f\n",f(a)==0?a:b);
}
do
{
a=c;
c=(((a*f(b)-(b*f(a)))/(f(b)-f(a))));
printf("%2d\t%f\t%f\t%f\t%f\t,i++,a,b,c,f(c));
if(f(c)==0)
{
break;
}
else if(f(a)*f(c)<0)
{
b=c;
}
else if(a=c)
{
error=fabs(c-d);
}
else if(i==1)
{
printf("\n");
}
else
{
printf("%f\n",error);
}
}
while(error>0.00005)
printf("root is%f\n",c);
return 0;
}
printf("output is %f",x);
return 0;
}