質問編集履歴

4

コードの追記

2017/12/11 13:00

投稿

ryo_py
ryo_py

スコア25

test CHANGED
File without changes
test CHANGED
@@ -19,3 +19,97 @@
19
19
 
20
20
 
21
21
  わかる方いましたら教えていただけると助かります。
22
+
23
+
24
+
25
+ ```C
26
+
27
+ #include <stdio.h>
28
+
29
+ #include <stdlib.h>
30
+
31
+ #include <math.h>
32
+
33
+
34
+
35
+ typedef struct {
36
+
37
+ double x;//x coordinate
38
+
39
+ double y;//y coordinate
40
+
41
+ } Point;
42
+
43
+
44
+
45
+ /*構造体 struct Rectangle型を定義*/
46
+
47
+ /*またはtypedefで Rectangle構造体型を定義*/
48
+
49
+ typedef struct {
50
+
51
+ Point P1;
52
+
53
+ Point P2;
54
+
55
+ } Rectangle;
56
+
57
+
58
+
59
+ double rectangleArea(Rectangle R);
60
+
61
+
62
+
63
+ int main(void) {
64
+
65
+ Rectangle R;//長方形 R
66
+
67
+ double s;//Rの面積
68
+
69
+
70
+
71
+ /*長方形 Rの(対角)座標を入力する文 */
72
+
73
+ printf("P1.x? ");
74
+
75
+ scanf("%lf \n", &R.P1.x);
76
+
77
+ printf("P1.y? ");
78
+
79
+ scanf("%lf \n", &R.P1.y);
80
+
81
+ printf("P2.x? ");
82
+
83
+ scanf("%lf \n", &R.P2.x);
84
+
85
+ printf("P2.y? ");
86
+
87
+ scanf("%lf \n", &R.P2.y);
88
+
89
+
90
+
91
+ /*rectagleAreaを呼び出して長方形 Rの面積を計算する文*/
92
+
93
+ s = rectangleArea(R);
94
+
95
+ printf("Areal = %.2f\n", s);
96
+
97
+ return 0;
98
+
99
+ }
100
+
101
+
102
+
103
+ double rectangleArea(Rectangle R) {
104
+
105
+ /*長方形 Rの面積を計算して返却するコード*/
106
+
107
+ double Area;
108
+
109
+ Area = (R.P2.x - R.P1.x) * (R.P2.y -R.P1.y);
110
+
111
+ return Area;
112
+
113
+ }
114
+
115
+ ```

3

2017/12/11 13:00

投稿

ryo_py
ryo_py

スコア25

test CHANGED
File without changes
test CHANGED
@@ -6,9 +6,9 @@
6
6
 
7
7
  x? 3 /* 3と入力してEnterをした*/
8
8
 
9
- 2 /* y?に行きたいのに入力待ちになる*/
9
+ 2 /* y?に行きたいのに入力待ちになり、何か数字を入力すとy?に行く(今回は2を入力した)*/
10
10
 
11
- y?5 /* 何か数字を入力するとy?に行く(今回は2を入力した)*/
11
+ y?5
12
12
 
13
13
  z?6
14
14
 

2

2017/12/11 11:15

投稿

ryo_py
ryo_py

スコア25

test CHANGED
File without changes
test CHANGED
File without changes

1

2017/12/11 11:14

投稿

ryo_py
ryo_py

スコア25

test CHANGED
File without changes
test CHANGED
@@ -1,6 +1,6 @@
1
1
  C言語で printf と scanf を使い変数に値を入力するコードで、なぜか初めの変数だけ2回入力することになってしまいます。
2
2
 
3
- どういうことかというと下のような感じです。
3
+ どういうことかというと下のような感じです。
4
4
 
5
5
 
6
6