質問編集履歴
2
文法の修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -35,10 +35,17 @@
|
|
35
35
|
#include <stdio.h>
|
36
36
|
#include <math.h>
|
37
37
|
|
38
|
-
float f(x)
|
38
|
+
float f(float x){
|
39
|
-
float df(x);
|
40
|
-
f(x) = x - cos(x);
|
39
|
+
f(x) = x - cos(x);
|
40
|
+
return f(x) ;
|
41
|
+
}
|
42
|
+
|
43
|
+
float df(float x){
|
41
|
-
df(x) = 1.0 + sin(x);
|
44
|
+
df(x) = 1.0 + sin(x);
|
45
|
+
return df(x);
|
46
|
+
}
|
47
|
+
|
48
|
+
|
42
49
|
int main(){
|
43
50
|
float f(x);
|
44
51
|
float df(x);
|
@@ -53,42 +60,41 @@
|
|
53
60
|
break;
|
54
61
|
}}
|
55
62
|
|
63
|
+
|
64
|
+
|
56
65
|
```
|
57
66
|
```ここに言語を入力
|
67
|
+
kadai11_1.c: In function ‘f’:
|
68
|
+
kadai11_1.c:5:14: error: lvalue required as left operand of assignment
|
69
|
+
f(x) = x - cos(x);
|
70
|
+
^
|
71
|
+
kadai11_1.c: In function ‘df’:
|
72
|
+
kadai11_1.c:10:15: error: lvalue required as left operand of assignment
|
73
|
+
df(x) = 1.0 + sin(x);
|
74
|
+
^
|
75
|
+
kadai11_1.c: In function ‘main’:
|
58
|
-
kadai11_1.c:
|
76
|
+
kadai11_1.c:16:5: warning: parameter names (without types) in function declaration
|
59
77
|
float f(x);
|
60
78
|
^~~~~
|
79
|
+
kadai11_1.c:16:11: error: conflicting types for ‘f’
|
80
|
+
float f(x);
|
81
|
+
^
|
82
|
+
kadai11_1.c:16:5: note: an argument type that has a default promotion can’t match an empty parameter name list declaration
|
83
|
+
float f(x);
|
84
|
+
^~~~~
|
85
|
+
kadai11_1.c:4:11: note: previous definition of ‘f’ was here
|
86
|
+
float f(float x){
|
87
|
+
^
|
61
|
-
kadai11_1.c:
|
88
|
+
kadai11_1.c:17:5: warning: parameter names (without types) in function declaration
|
62
89
|
float df(x);
|
63
90
|
^~~~~
|
64
|
-
kadai11_1.c:6:5: warning: data definition has no type or storage class
|
65
|
-
f(x) = x - cos(x);
|
66
|
-
^
|
67
|
-
kadai11_1.c:6:5: warning: type defaults to ‘int’ in declaration of ‘f’ [-Wimplicit-int]
|
68
|
-
kadai11_1.c:6:5: warning: parameter names (without types) in function declaration
|
69
|
-
kadai11_1.c:6:5: error: function ‘f’ is initialized like a variable
|
70
|
-
kadai11_1.c:6:5: error: conflicting types for ‘f’
|
71
|
-
kadai11_1.c:4:11: note: previous declaration of ‘f’ was here
|
72
|
-
float f(x);
|
73
|
-
^
|
74
|
-
kadai11_1.c:6:12: error: ‘x’ undeclared here (not in a function)
|
75
|
-
f(x) = x - cos(x);
|
76
|
-
^
|
77
|
-
kadai11_1.c:7:5: warning: data definition has no type or storage class
|
78
|
-
df(x) = 1.0 + sin(x);
|
79
|
-
^~
|
80
|
-
kadai11_1.c:7:5: warning: type defaults to ‘int’ in declaration of ‘df’ [-Wimplicit-int]
|
81
|
-
kadai11_1.c:7:5: warning: parameter names (without types) in function declaration
|
82
|
-
kadai11_1.c:7:5: error: function ‘df’ is initialized like a variable
|
83
|
-
kadai11_1.c:7:
|
91
|
+
kadai11_1.c:17:11: error: conflicting types for ‘df’
|
84
|
-
kadai11_1.c:5:11: note: previous declaration of ‘df’ was here
|
85
92
|
float df(x);
|
86
93
|
^~
|
87
|
-
kadai11_1.c: In function ‘main’:
|
88
|
-
kadai11_1.c:
|
94
|
+
kadai11_1.c:17:5: note: an argument type that has a default promotion can’t match an empty parameter name list declaration
|
89
|
-
float f(x);
|
95
|
+
float df(x);
|
90
96
|
^~~~~
|
91
|
-
kadai11_1.c:1
|
97
|
+
kadai11_1.c:9:11: note: previous definition of ‘df’ was here
|
92
|
-
float df(x)
|
98
|
+
float df(float x){
|
93
99
|
```
|
94
100
|
のようなエラーが出てしまいました
|
1
関数をmain外に記入
test
CHANGED
File without changes
|
test
CHANGED
@@ -29,4 +29,66 @@
|
|
29
29
|
|
30
30
|
のエラーが表示されています。どのように直したらよいのかわからないです。
|
31
31
|
|
32
|
+
追記
|
33
|
+
main 外に書けばいいとの指摘をいただいたので書き直したところ
|
34
|
+
```C
|
35
|
+
#include <stdio.h>
|
36
|
+
#include <math.h>
|
32
37
|
|
38
|
+
float f(x);
|
39
|
+
float df(x);
|
40
|
+
f(x) = x - cos(x);
|
41
|
+
df(x) = 1.0 + sin(x);
|
42
|
+
int main(){
|
43
|
+
float f(x);
|
44
|
+
float df(x);
|
45
|
+
float x;
|
46
|
+
int i;
|
47
|
+
|
48
|
+
x = 1.0;
|
49
|
+
for (i = 1; i <= 100;i++){;
|
50
|
+
x = x-f(x)/df(x);
|
51
|
+
if(fabs(f(x)) <= exp(-6));
|
52
|
+
printf("x=%f.\n",x);
|
53
|
+
break;
|
54
|
+
}}
|
55
|
+
|
56
|
+
```
|
57
|
+
```ここに言語を入力
|
58
|
+
kadai11_1.c:4:5: warning: parameter names (without types) in function declaration
|
59
|
+
float f(x);
|
60
|
+
^~~~~
|
61
|
+
kadai11_1.c:5:5: warning: parameter names (without types) in function declaration
|
62
|
+
float df(x);
|
63
|
+
^~~~~
|
64
|
+
kadai11_1.c:6:5: warning: data definition has no type or storage class
|
65
|
+
f(x) = x - cos(x);
|
66
|
+
^
|
67
|
+
kadai11_1.c:6:5: warning: type defaults to ‘int’ in declaration of ‘f’ [-Wimplicit-int]
|
68
|
+
kadai11_1.c:6:5: warning: parameter names (without types) in function declaration
|
69
|
+
kadai11_1.c:6:5: error: function ‘f’ is initialized like a variable
|
70
|
+
kadai11_1.c:6:5: error: conflicting types for ‘f’
|
71
|
+
kadai11_1.c:4:11: note: previous declaration of ‘f’ was here
|
72
|
+
float f(x);
|
73
|
+
^
|
74
|
+
kadai11_1.c:6:12: error: ‘x’ undeclared here (not in a function)
|
75
|
+
f(x) = x - cos(x);
|
76
|
+
^
|
77
|
+
kadai11_1.c:7:5: warning: data definition has no type or storage class
|
78
|
+
df(x) = 1.0 + sin(x);
|
79
|
+
^~
|
80
|
+
kadai11_1.c:7:5: warning: type defaults to ‘int’ in declaration of ‘df’ [-Wimplicit-int]
|
81
|
+
kadai11_1.c:7:5: warning: parameter names (without types) in function declaration
|
82
|
+
kadai11_1.c:7:5: error: function ‘df’ is initialized like a variable
|
83
|
+
kadai11_1.c:7:5: error: conflicting types for ‘df’
|
84
|
+
kadai11_1.c:5:11: note: previous declaration of ‘df’ was here
|
85
|
+
float df(x);
|
86
|
+
^~
|
87
|
+
kadai11_1.c: In function ‘main’:
|
88
|
+
kadai11_1.c:9:5: warning: parameter names (without types) in function declaration
|
89
|
+
float f(x);
|
90
|
+
^~~~~
|
91
|
+
kadai11_1.c:10:5: warning: parameter names (without types) in function declaration
|
92
|
+
float df(x);
|
93
|
+
```
|
94
|
+
のようなエラーが出てしまいました
|