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