teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

2021/02/06 09:39

投稿

tosakagreen
tosakagreen

スコア1

title CHANGED
File without changes
body CHANGED
@@ -82,19 +82,25 @@
82
82
  #include "complex.h"
83
83
  #define sqr(x) ((x) * (x)) /* xの2乗を求める関数形式マクロ */
84
84
  /* 複素数uとvの加算結果を返す関数 */ complex comp_add (complex u, complex v) {
85
- }
85
+
86
86
  complex w;
87
+
87
- w.real = u.real + v.real; w.imag = u.imag + v.imag;
88
+  w.real = u.real + v.real;
89
+   w.imag = u.imag + v.imag;
90
+
88
91
  return (w);
92
+ }
89
93
  /* 複素数uの絶対値を返す関数 */ double comp_abs (complex u)
90
94
  {
91
95
  return (sqrt(sqr(u.real) + sqr(u.imag)));
92
96
  }
93
- /* 複素数uの偏角を返す関数 */ double comp_arg (complex u)
97
+ /* 複素数uの偏角を返す関数 */
98
+ double comp_arg (complex u)
94
99
  {
95
100
  return (atan2(u.imag, u.real));
96
101
  }
97
- /* 読み込んだ複素数を返す関数 */ complex comp_scan (void)
102
+ /* 読み込んだ複素数を返す関数 */
103
+ complex comp_scan (void)
98
104
  {
99
105
 
100
106
  complex z;

3

2021/02/06 09:39

投稿

tosakagreen
tosakagreen

スコア1

title CHANGED
File without changes
body CHANGED
@@ -78,7 +78,8 @@
78
78
  *
79
79
  * 複素数の演算を記述するプログラム */
80
80
  #include <stdio.h>
81
- #include <math.h> /* コンパイルオプション -lm を付ける */ #include "complex.h"
81
+ #include <math.h> /* コンパイルオプション -lm を付ける */
82
+ #include "complex.h"
82
83
  #define sqr(x) ((x) * (x)) /* xの2乗を求める関数形式マクロ */
83
84
  /* 複素数uとvの加算結果を返す関数 */ complex comp_add (complex u, complex v) {
84
85
  }

2

2021/02/06 09:36

投稿

tosakagreen
tosakagreen

スコア1

title CHANGED
File without changes
body CHANGED
@@ -73,20 +73,51 @@
73
73
  /* 読み込んだ複素数を返す関数 */
74
74
  void comp_print (complex z, form f);
75
75
 
76
+ /*
77
+ * complex.c
78
+ *
76
- /*符号反転して返関数*/
79
+ * 複素数の演算記述るプログラム */
80
+ #include <stdio.h>
81
+ #include <math.h> /* コンパイルオプション -lm を付ける */ #include "complex.h"
82
+ #define sqr(x) ((x) * (x)) /* xの2乗を求める関数形式マクロ */
83
+ /* 複素数uとvの加算結果を返す関数 */ complex comp_add (complex u, complex v) {
84
+ }
85
+ complex w;
86
+ w.real = u.real + v.real; w.imag = u.imag + v.imag;
87
+ return (w);
88
+ /* 複素数uの絶対値を返す関数 */ double comp_abs (complex u)
89
+ {
90
+ return (sqrt(sqr(u.real) + sqr(u.imag)));
91
+ }
77
- complex comp_neg (complex u);
92
+ /* 複素数uの偏角を返す関数 */ double comp_arg (complex u)
93
+ {
94
+ return (atan2(u.imag, u.real));
95
+ }
96
+ /* 読み込んだ複素数を返す関数 */ complex comp_scan (void)
97
+ {
78
98
 
99
+ complex z;
100
+
101
+ printf("Re: ");
102
+ scanf("%lf", &z.real);
103
+ printf("Im: ");
104
+ scanf("%lf", &z.imag);
105
+
106
+ return (z);
107
+ }
108
+
79
- /* 読み込んだ複素数を返す関数 */
109
+ /* 読み込んだ複素数を返す関数 */
80
- void comp_print (complex z, form f)
110
+ void comp_print (complex z, form f)
81
111
  {
82
- switch(f) {
112
+ switch(f) {
83
- case Orth :
113
+ case Orth :
84
- printf("%f+%fi\n", z.real, z.imag);
114
+ printf("%f+%fi\n", z.real, z.imag);
85
- break;
115
+ break;
86
- case Polar :
116
+ case Polar :
87
- printf("%fexp(%fi)\n", comp_abs(z), comp_arg(z));
117
+ printf("%fexp(%fi)\n", comp_abs(z), comp_arg(z));
88
- break;
118
+ break;
89
- }
119
+ }
90
- }
120
+ }
91
121
 
122
+
92
123
  ```

1

2021/02/06 09:34

投稿

tosakagreen
tosakagreen

スコア1

title CHANGED
File without changes
body CHANGED
@@ -4,8 +4,10 @@
4
4
  状況説明です。大学の課題で、複素数を2つ入力しの四則演算を求めよと言う課題が出ました。
5
5
  まず、複素数の和のソースコードを配られ、そこから拡張して作りなさいと言う物なんですけど、そもそもそのソースコードがエラーをはいて動かないです。写し間違えないように3.4回見直して、調べたらもしたのですがどうしても解決しません。
6
6
  どこを直したら良いですか?
7
+
7
- 大学からの複素数の和のコード
8
+ ```
9
+
8
- ```/* 複素数の和を求めるプログラム
10
+ /* 複素数の和を求めるプログラム
9
11
  */
10
12
 
11
13