質問編集履歴

3

変更ミス

2021/01/19 23:20

投稿

natahatahata
natahatahata

スコア2

test CHANGED
File without changes
test CHANGED
@@ -4,55 +4,31 @@
4
4
 
5
5
 
6
6
 
7
- ./Main.c:2:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
7
+ ./Main.c:3:1: warning: return type defaults to ‘int’ [-Wimplicit-int]
8
8
 
9
- 2 | main()
9
+ 3 | main()
10
10
 
11
11
  | ^~~~
12
12
 
13
13
  ./Main.c: In function ‘main’:
14
14
 
15
- ./Main.c:14:26: warning: implicit declaration of function ‘sqrt [-Wimplicit-function-declaration]
15
+ ./Main.c:8:3: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
16
16
 
17
- 14 | if(x>=-0.1*0.01*(1+sqrt(5))/2 and x<=-0.1*0.01*(1+sqrt(5))/2){
17
+ 8 | scanf("%d",&n);
18
18
 
19
- | ^~~~
19
+ | ^~~~~~~~~~~~~~
20
20
 
21
- ./Main.c:14:26: warning: incompatible implicit declaration of built-in functionsqrt
21
+ ./Main.c:12:5: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result [-Wunused-result]
22
22
 
23
- ./Main.c:2:1: note: include ‘<math.h>’ or provide a declaration of ‘sqrt’
23
+ 12 | scanf("%f",&x[i]);
24
24
 
25
- 1 | #include <stdio.h>
25
+ | ^~~~~~~~~~~~~~~~~
26
26
 
27
- +++ |+#include <math.h>
27
+ /tmp/cc24RTvI.o: In function `main':
28
28
 
29
- 2 | main()
29
+ Main.c:(.text.startup+0x95): undefined reference to `narabekae'
30
30
 
31
- ./Main.c:14:36: error: expected ‘)’ before and’
31
+ collect2: error: ld returned 1 exit status
32
-
33
- 14 | if(x>=-0.1*0.01*(1+sqrt(5))/2 and x<=-0.1*0.01*(1+sqrt(5))/2){
34
-
35
- | ~ ^~~~
36
-
37
- | )
38
-
39
- ./Main.c:17:13: error: expected ‘;’ before ‘}’ token
40
-
41
- 17 | }i=i+1
42
-
43
- | ^
44
-
45
- | ;
46
-
47
- 18 | }
48
-
49
- | ~
50
-
51
- ./Main.c:18:10: error: expected declaration or statement at end of input
52
-
53
- 18 | }
54
-
55
- | ^
56
32
 
57
33
 
58
34
 

2

題名間違い

2021/01/19 23:20

投稿

natahatahata
natahatahata

スコア2

test CHANGED
@@ -1 +1 @@
1
- an/an−1 の値が(1 + √ 5)/2 の ±0.1 % の範囲入る最小の n を求めるプログラム(anはフィボナッチ数列)
1
+ クイックソートついて
test CHANGED
File without changes

1

打っている途中で投稿した

2021/01/19 23:16

投稿

natahatahata
natahatahata

スコア2

test CHANGED
File without changes
test CHANGED
@@ -56,4 +56,104 @@
56
56
 
57
57
 
58
58
 
59
+ 自分の書いたプログラムはこれです
60
+
61
+ #include<stdio.h>
62
+
63
+ void narabekae(int,float[]);
64
+
65
+ main()
66
+
67
+ {
68
+
69
+ int i,j,n;
70
+
71
+ float x[1000];
72
+
73
+ printf("Please input n.");
74
+
75
+ scanf("%d",&n);
76
+
77
+ i=0;
78
+
79
+ while (i<=n-1){
80
+
81
+ printf("Please input %dth data.",i);
82
+
83
+ scanf("%f",&x[i]);
84
+
85
+ i=i+1;
86
+
87
+ }
88
+
89
+ narabekae(n,x);
90
+
91
+ i=0;
92
+
93
+ while(i<=n-1){
94
+
95
+ printf("%f\n",x[i]);
96
+
97
+ i=i+1;
98
+
99
+ }
100
+
101
+ }
102
+
103
+
104
+
105
+ void swap(int* a, int* b)
106
+
107
+ {
108
+
109
+ int t = *a;
110
+
111
+ *a = *b;
112
+
59
- じぶんのかいた
113
+ *b = t;
114
+
115
+ }
116
+
117
+
118
+
119
+ int partition (int array[], int l, int r) {
120
+
121
+ int pivot = array[r];
122
+
123
+ int i = (l - 1);
124
+
125
+
126
+
127
+ for (int j = l; j <= r - 1; j++) {
128
+
129
+ if (array[j] <= pivot) {
130
+
131
+ i++;
132
+
133
+ swap(&array[i], &array[j]);
134
+
135
+ }
136
+
137
+ }
138
+
139
+ swap(&array[i + 1], &array[r]);
140
+
141
+ return (i + 1);
142
+
143
+ }
144
+
145
+
146
+
147
+ void quickSort(int array[], int l, int r) {
148
+
149
+ if (l < r) {
150
+
151
+ int pivot = partition(array, l, r);
152
+
153
+ quickSort(array, l, pivot - 1);
154
+
155
+ quickSort(array, pivot + 1, r);
156
+
157
+ }
158
+
159
+ }