質問編集履歴

4

2021/02/06 09:39

投稿

tosakagreen
tosakagreen

スコア1

test CHANGED
File without changes
test CHANGED
@@ -166,14 +166,22 @@
166
166
 
167
167
  /* 複素数uとvの加算結果を返す関数 */ complex comp_add (complex u, complex v) {
168
168
 
169
- }
169
+
170
170
 
171
171
  complex w;
172
172
 
173
+
174
+
173
- w.real = u.real + v.real; w.imag = u.imag + v.imag;
175
+  w.real = u.real + v.real;
176
+
177
+   w.imag = u.imag + v.imag;
178
+
179
+
174
180
 
175
181
  return (w);
176
182
 
183
+ }
184
+
177
185
  /* 複素数uの絶対値を返す関数 */ double comp_abs (complex u)
178
186
 
179
187
  {
@@ -182,7 +190,9 @@
182
190
 
183
191
  }
184
192
 
185
- /* 複素数uの偏角を返す関数 */ double comp_arg (complex u)
193
+ /* 複素数uの偏角を返す関数 */
194
+
195
+ double comp_arg (complex u)
186
196
 
187
197
  {
188
198
 
@@ -190,7 +200,9 @@
190
200
 
191
201
  }
192
202
 
193
- /* 読み込んだ複素数を返す関数 */ complex comp_scan (void)
203
+ /* 読み込んだ複素数を返す関数 */
204
+
205
+ complex comp_scan (void)
194
206
 
195
207
  {
196
208
 

3

2021/02/06 09:39

投稿

tosakagreen
tosakagreen

スコア1

test CHANGED
File without changes
test CHANGED
@@ -158,7 +158,9 @@
158
158
 
159
159
  #include <stdio.h>
160
160
 
161
- #include <math.h> /* コンパイルオプション -lm を付ける */ #include "complex.h"
161
+ #include <math.h> /* コンパイルオプション -lm を付ける */
162
+
163
+ #include "complex.h"
162
164
 
163
165
  #define sqr(x) ((x) * (x)) /* xの2乗を求める関数形式マクロ */
164
166
 

2

2021/02/06 09:36

投稿

tosakagreen
tosakagreen

スコア1

test CHANGED
File without changes
test CHANGED
@@ -148,35 +148,97 @@
148
148
 
149
149
 
150
150
 
151
- /*符号を反転して返す関数*/
152
-
153
- complex comp_neg (complex u);
154
-
155
-
156
-
157
- /* 読み込んだ複素数を関数 */
158
-
159
- void comp_print (complex z, form f)
160
-
161
- {
162
-
163
- switch(f) {
164
-
165
- case Orth :
166
-
167
- printf("%f+%fi\n", z.real, z.imag);
168
-
169
- break;
170
-
171
- case Polar :
172
-
173
- printf("%fexp(%fi)\n", comp_abs(z), comp_arg(z));
174
-
175
- break;
176
-
177
- }
178
-
179
- }
151
+ /*
152
+
153
+ * complex.c
154
+
155
+ *
156
+
157
+ * 複素数の演算記述るプログラム */
158
+
159
+ #include <stdio.h>
160
+
161
+ #include <math.h> /* コンパイルオプション -lm を付ける */ #include "complex.h"
162
+
163
+ #define sqr(x) ((x) * (x)) /* xの2乗を求める関数形式マクロ */
164
+
165
+ /* 複素数uとvの加算結果を返す関数 */ complex comp_add (complex u, complex v) {
166
+
167
+ }
168
+
169
+ complex w;
170
+
171
+ w.real = u.real + v.real; w.imag = u.imag + v.imag;
172
+
173
+ return (w);
174
+
175
+ /* 複素数uの絶対値を返す関数 */ double comp_abs (complex u)
176
+
177
+ {
178
+
179
+ return (sqrt(sqr(u.real) + sqr(u.imag)));
180
+
181
+ }
182
+
183
+ /* 複素数uの偏角を返す関数 */ double comp_arg (complex u)
184
+
185
+ {
186
+
187
+ return (atan2(u.imag, u.real));
188
+
189
+ }
190
+
191
+ /* 読み込んだ複素数を返す関数 */ complex comp_scan (void)
192
+
193
+ {
194
+
195
+
196
+
197
+ complex z;
198
+
199
+
200
+
201
+ printf("Re: ");
202
+
203
+ scanf("%lf", &z.real);
204
+
205
+ printf("Im: ");
206
+
207
+ scanf("%lf", &z.imag);
208
+
209
+
210
+
211
+ return (z);
212
+
213
+ }
214
+
215
+
216
+
217
+ /* 読み込んだ複素数を返す関数 */
218
+
219
+ void comp_print (complex z, form f)
220
+
221
+ {
222
+
223
+ switch(f) {
224
+
225
+ case Orth :
226
+
227
+ printf("%f+%fi\n", z.real, z.imag);
228
+
229
+ break;
230
+
231
+ case Polar :
232
+
233
+ printf("%fexp(%fi)\n", comp_abs(z), comp_arg(z));
234
+
235
+ break;
236
+
237
+ }
238
+
239
+ }
240
+
241
+
180
242
 
181
243
 
182
244
 

1

2021/02/06 09:34

投稿

tosakagreen
tosakagreen

スコア1

test CHANGED
File without changes
test CHANGED
@@ -10,9 +10,13 @@
10
10
 
11
11
  どこを直したら良いですか?
12
12
 
13
- 大学からの複素数の和のコード
14
13
 
14
+
15
+ ```
16
+
17
+
18
+
15
- ```/* 複素数の和を求めるプログラム
19
+ /* 複素数の和を求めるプログラム
16
20
 
17
21
  */
18
22