Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit657d979

Browse files
authored
Create binarys.c
1 parentb895794 commit657d979

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

‎Searches/binarys.c

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include<stdio.h>
2+
3+
intmain()
4+
{
5+
intc,first,last,middle,n,search,array[100];
6+
7+
printf("Enter number of elements\n");
8+
scanf("%d",&n);
9+
10+
printf("Enter %d integers\n",n);
11+
12+
for (c=0;c<n;c++)
13+
scanf("%d",&array[c]);
14+
15+
printf("Enter value to find\n");
16+
scanf("%d",&search);
17+
18+
first=0;
19+
last=n-1;
20+
middle= (first+last)/2;
21+
22+
while (first <=last) {
23+
if (array[middle]<search)
24+
first=middle+1;
25+
elseif (array[middle]==search) {
26+
printf("%d found at location %d.\n",search,middle+1);
27+
break;
28+
}
29+
else
30+
last=middle-1;
31+
32+
middle= (first+last)/2;
33+
}
34+
if (first>last)
35+
printf("Not found! %d isn't present in the list.\n",search);
36+
37+
return0;
38+
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp