-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbissectionmethod.c
59 lines (50 loc) · 1006 Bytes
/
bissectionmethod.c
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
53
54
55
56
57
58
59
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
void main()
{
float acc,error,a,b,c,fc;
float answerarray[100];
answerarray[0]=0;
float sum=0;
int i,d;
int itno=1;
printf("enter the degree of the polynomial");
scanf("%d",&d);
int *p;
p=(int *)malloc((d+1)*sizeof(int));
printf("enter the degree of accuracy of the answer");
scanf("%f",&acc);
for(i=0;i<(d+1);i++)
{
printf("enter the coefficients of the polynomial x power %d",(d-i));
scanf("%d",&p[i]);
}
printf("enter any a so that fa<0");
scanf("%f",&a);
printf("enter any b so that fb>0");
scanf("%f",&b);
printf("a b c fc\n");
do{
c=(a+b)/2;
for(i=d;i>=0;i--)
{
sum=sum+p[i]*pow(c,(d-i));
}
fc=sum;
sum=0;
printf("%f %f %f %f\n",a,b,c,fc);
if(fc>0)
{
b=c;
}
else
{
a=c;
}
answerarray[itno]=c;
error=answerarray[itno]-answerarray[itno-1];
itno++;
}
while(fabs(error)>acc);
}