質問編集履歴

2

コードコード41行目()の消去、43行目の修正

2022/01/01 13:15

投稿

KNTN
KNTN

スコア25

test CHANGED
File without changes
test CHANGED
@@ -88,8 +88,6 @@
88
88
 
89
89
  if(*g < EPS)
90
90
 
91
- {
92
-
93
91
 
94
92
 
95
93
  return simpson(double a, double b, int 2.0*n, double (*f)());
@@ -100,16 +98,6 @@
100
98
 
101
99
  }
102
100
 
103
- }
104
-
105
-
106
-
107
- double funk(double x) {
108
-
109
- return (exp(x));
110
-
111
- }
112
-
113
101
  ```
114
102
 
115
103
 
@@ -118,6 +106,6 @@
118
106
 
119
107
 
120
108
 
121
- ![イメージ説明](7cfadcd6e88b6723ea3e21b92274fc4e.png)
109
+ ![イメージ説明](8f615a987c6172f15164cce3fad4a5bb.png)
122
110
 
123
111
  よろしくお願いします

1

コードの修正、およびエラーメッセージの掲載

2022/01/01 13:15

投稿

KNTN
KNTN

スコア25

test CHANGED
File without changes
test CHANGED
@@ -2,94 +2,122 @@
2
2
 
3
3
 
4
4
 
5
+
6
+
5
- ソースコード
7
+ ```C
8
+
9
+ #include<stdio.h>
10
+
11
+ #include <math.h>
6
12
 
7
13
 
8
14
 
9
- #include<stdio.h>
15
+ double funk(double x);
10
16
 
11
- #include <math.h>
12
-
13
- double exp(double x);
14
-
15
- double simpson(double a, double b, int n, double (*f)());
17
+ double simpson(double a, double b, int n, double (*f)());
16
18
 
17
19
 
18
20
 
19
- int main(void){
21
+ int main(void)
20
22
 
21
- double *g; d
23
+ {
22
24
 
23
- ouble EPS=*g;
25
+ double *g;
24
26
 
25
- printf("正の整数を入力してください->",EPS);
27
+ double EPS=*g;
26
28
 
27
- scanf("%d",EPS);
29
+ printf("sei no seisuu wo nyuuryoku ->",EPS);
28
30
 
29
- printf("exp(x)を[0,1]で積分します.分割数は%dです\n",2*EPS);
31
+ scanf("%d",EPS);
30
-
31
- printf("結果は%20.15fです\n",simpson(0, 1.0, EPS, exp));
32
32
 
33
33
 
34
34
 
35
- return 0; }
35
+ printf("exp(x) wo [0,1] de sekibun simasu. bunkatu suu ha %d desu \n",2*EPS);
36
36
 
37
+ printf("result is %20.15f\n",simpson(0, 1.0, EPS, funk));
37
38
 
38
-
39
- double simpson(double a, double b, int n, double (*f)())
40
-
41
-
42
-
43
- {
44
-
45
- double S,h;
46
-
47
- int i;
48
-
49
- h=(b-a)/(2.0*n);
50
-
51
- S=((*f)(a)+(*f)(b));
52
-
53
- for (i=1;i<n;i++)
54
-
55
- {
56
-
57
- S += 4.0*(*f)(a+(2.0*i-1.0)*h)+2.0*(*f)(a+2.0*i*h);
58
-
59
- }
60
-
61
- S += 4.0*(*f)(a+(2.0*n-1.0)*h);
62
-
63
- S *= h/3.0; return S;
64
-
65
- }
66
-
67
-
68
-
69
- double EPS(double *g) {
70
-
71
-
72
-
73
- int n;
74
-
75
- fabs(simpson(0, 1.0, 2.0*n, exp)-simpson(0, 1.0, n, exp))=*g;
76
-
77
-
78
-
79
- if(*g<EPS){
80
-
81
- return simpson(double a, double b, int 2.0*n, double (*f)());
82
-
83
- else return 1; }
39
+ return 0;
84
-
85
- }
86
-
87
- double exp(double x) {
88
-
89
- return(exp(x));
90
40
 
91
41
  }
92
42
 
93
43
 
94
44
 
45
+ double simpson(double a, double b, int n, double (*f)()) {
46
+
47
+
48
+
49
+ double S,h;
50
+
51
+ int i;
52
+
53
+
54
+
55
+ h=(b-a)/(2.0*n);
56
+
57
+
58
+
59
+ S=((*f)(a)+(*f)(b));
60
+
61
+
62
+
63
+ for (i=1;i<n;i++)
64
+
65
+ {
66
+
67
+ S += 4.0*(*f)(a+(2.0*i-1.0)*h)+2.0*(*f)(a+2.0*i*h); }
68
+
69
+
70
+
71
+ S += 4.0*(*f)(a+(2.0*n-1.0)*h); S *= h/3.0; return S;
72
+
73
+ }
74
+
75
+
76
+
77
+ double EPS(double g)
78
+
79
+ {
80
+
81
+ int n;
82
+
83
+
84
+
85
+ *g = (simpson(0, 1.0, 2.0*n, funk)- simpson(0, 1.0, n, funk));
86
+
87
+
88
+
89
+ if(*g < EPS)
90
+
91
+ {
92
+
93
+
94
+
95
+ return simpson(double a, double b, int 2.0*n, double (*f)());
96
+
97
+
98
+
99
+ else return 1;
100
+
101
+ }
102
+
103
+ }
104
+
105
+
106
+
107
+ double funk(double x) {
108
+
109
+ return (exp(x));
110
+
111
+ }
112
+
113
+ ```
114
+
115
+
116
+
117
+ エラーメッセージ(コピペできなかったため写真を添付します)
118
+
119
+
120
+
121
+ ![イメージ説明](7cfadcd6e88b6723ea3e21b92274fc4e.png)
122
+
95
123
  よろしくお願いします