Created
August 24, 2019 13:45
-
-
Save midorikocak/d26c9994cc2eff2844a0ef2810232017 to your computer and use it in GitHub Desktop.
Binary Search
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int eb=9; | |
int ek=0; | |
int aranan = 120; | |
int deneme=1; | |
int bakilan = 0; | |
int dizi[10]={10,19,28,41,59,67,75,80,86,94}; | |
void logla(ek,eb,aranan,bakilan,deneme) | |
{ | |
printf("%d.denemede %d-%d araliginda %d arandi. \n",deneme,ek,eb,aranan); | |
printf("%d.elemana bakildi.",bakilan); | |
} | |
int main() | |
{ | |
bakilan=(eb+ek)/2; | |
while(ek<=eb) | |
{ | |
logla(ek,eb,aranan,bakilan,deneme); | |
if(aranan==dizi[bakilan]) | |
{ | |
printf("sayi bulundu"); | |
return 1; | |
} | |
else if (aranan>dizi[bakilan]) | |
{ | |
printf("sayi yüksek"); | |
ek=bakilan+1; | |
} | |
else if (aranan < dizi[bakilan]) | |
{ | |
printf("sayi küçük"); | |
eb=bakilan-1; | |
} | |
bakilan=(ek+eb)/2; | |
deneme++; | |
} | |
printf("sayi bulunamadi"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment