01: #include <stdio.h>
02: #include <math.h>
03: #define EPS 1e-6
04:
05: double f(double x);
06:
07:
08:
09:
10: int main(void){
11: double a, b, c, temp;
12:
13:
14: do{
15: printf("左端 aの値?\t");
16: scanf("%lf%*c",&a);
17: printf("右端 bの値?\t");
18: scanf("%lf%*c",&b);
19: }while(f(a)*f(b)>0);
20:
21:
22:
23: if(a>b){
24: temp=a;
25: a=b;
26: b=temp;
27: }
28:
29:
30:
31: while(b-a > EPS){
32: c=(a+b)/2;
33: if(f(c)*f(a)<0){
34: b=c;
35: }else{
36: a=c;
37: }
38: }
39:
40:
41:
42: printf("answer =\t%0.15f\n", c);
43:
44:
45: return 0;
46: }
47:
48:
49:
50:
51:
52:
53: double f(double x){
54: double y;
55:
56: y=x+exp(x)+sin(x);
57:
58: return y;
59: }