C
- @Linda_pp
- 清楚なC++メイドBOT
- 長谷川一輝
- @jj1bdx
- 安藤敏彦
- Siv3D
- @hnokx
- @ishidakei
- TAKEI Yuya
- I (@wx257osn2)
- Tommy6
- @nekketsuuu
- LouiS0616
- @volanja
- 大鎌広
- むてら
- ガチKGB
- 三重野賢人
x
36
1
2
int main()
3
{
4
int element;
5
int arr[100], n, pos=0;
6
int i;
7
int low = 0;
8
int high = sizeof(arr)-1;
9
int mid;
10
printf("Enter array size [1-100]: ");
11
scanf("%d", &n);
12
13
printf("Enter element: ");
14
scanf("%d", &element);
15
16
printf("Enter array elements: ");
17
for(i=0; i<n; i++)
18
scanf("%d", &arr[i]);
19
20
21
while (low <= high) {
22
mid = (low + high)/2;
23
24
if (arr[mid] == element) {
25
return mid;
26
}
27
if (arr[mid] < element) {
28
low = mid;
29
} else {
30
high = mid;
31
}
32
}
33
34
return 0;
35
}
36
$ gcc prog.c -Wall -Wextra -std=c99 -pedantic
Stdin
1 1 1
Start
prog.c: In function 'main': prog.c:17:4: warning: this 'for' clause does not guard... [-Wmisleading-indentation] 17 | for(i=0; i<n; i++) | ^~~ prog.c:21:5: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for' 21 | while (low <= high) { | ^~~~~ prog.c:5:21: warning: unused variable 'pos' [-Wunused-variable] 5 | int arr[100], n, pos=0; | ^~~
Killed
Finish