質問編集履歴
2
test
CHANGED
File without changes
|
test
CHANGED
@@ -88,4 +88,90 @@
|
|
88
88
|
|
89
89
|
```
|
90
90
|
|
91
|
+
|
92
|
+
|
93
|
+
訂正
|
94
|
+
|
95
|
+
```c
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
#include <stdio.h>
|
100
|
+
|
101
|
+
#include <math.h>
|
102
|
+
|
103
|
+
#include<stdlib.h>
|
104
|
+
|
105
|
+
double f(double x);
|
106
|
+
|
107
|
+
double power(double x, int n);
|
108
|
+
|
109
|
+
int main(void){
|
110
|
+
|
111
|
+
double eps=1.0e-13;
|
112
|
+
|
113
|
+
double a=1.0, b=2.0;
|
114
|
+
|
115
|
+
double u,c;
|
116
|
+
|
117
|
+
int k;
|
118
|
+
|
119
|
+
|
120
|
+
|
121
|
+
for(k=0; fabs(a-b)>eps; k++){
|
122
|
+
|
123
|
+
c=(a+b)/2;
|
124
|
+
|
125
|
+
if(f(c)*f(a)<=0) b=c;
|
126
|
+
|
127
|
+
else a=c;
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
printf("ans=%.13f \n",c);
|
132
|
+
|
133
|
+
u=a-b;
|
134
|
+
|
135
|
+
printf("k=%d,a=%lf,b=%lf,u(a-k)=%lf\n",k,a,b,u);
|
136
|
+
|
137
|
+
return 0;
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
double f(double x){
|
142
|
+
|
143
|
+
double x2,y,k;
|
144
|
+
|
145
|
+
double exp(double x);
|
146
|
+
|
147
|
+
k=exp(x);
|
148
|
+
|
149
|
+
x2=power(x,2);
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
y=k-x2-2;
|
154
|
+
|
155
|
+
return y;
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
double power(double x, int n){
|
162
|
+
|
163
|
+
if(n==0) return 1;
|
164
|
+
|
165
|
+
else
|
166
|
+
|
167
|
+
return x*power(x,n-1);
|
168
|
+
|
169
|
+
}
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
```
|
174
|
+
|
175
|
+
‘exp’に対する定義されていない参照です。とメッセージがでます。。
|
176
|
+
|
91
177
|
他にも間違えている点がありましたら、教えていただけると嬉しいです。
|
1
test
CHANGED
File without changes
|
test
CHANGED
@@ -58,11 +58,15 @@
|
|
58
58
|
|
59
59
|
double x2,y;
|
60
60
|
|
61
|
+
float expf(float x);
|
62
|
+
|
63
|
+
|
64
|
+
|
61
65
|
x2=power(x,2);
|
62
66
|
|
63
67
|
|
64
68
|
|
65
|
-
y=exp()-x2-2;
|
69
|
+
y=expf(x)-x2-2;
|
66
70
|
|
67
71
|
return y;
|
68
72
|
|