Find an Element Using BINARY SEARCH in C | C Programming

preview_player
Показать описание
In this video, I am going to explain how to find an element using binary search in c programming. This video is helpful for those who want to understand the logic of binary search. So watch the complete video, do like , share and subscribe to my channel. Thank you.
Рекомендации по теме
Комментарии
Автор

Is this code is right for this question:


#include<stdio.h>

void main ()
{ int a [10]={1, 4, 45, 23, 34, 76, 39, 80, 56, 48};
int i, sn, count = 0 ;

printf("The list is :\n");
for ( i = 0 ; i < 10; i ++ )
{ printf ( " %d ", a [ i ] ) ; }
printf ( " Enter a searching number: ") ;
scanf ( "%d", &sn ) ;
{ for ( i = 0 ; i <10 ; i ++ )
{ if ( a [ i ] == sn )
{ count++;
break;
}
}
}
if(count!=0)
printf("%d is found at a location %d.", sn, i+1);
else printf ( "%d is not found in the list.", sn ) ;
}

__sora__.