Posts

Showing posts from April, 2022

Program of Binary search as same linear search but differ.

  Binary search is also a searching technique or method in which we divide (beginning element + end element) by 2 give middle and check the lie between element. #include <stdio.h> int main () {     int list [ 10 ]={ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 }; //sorted array     int search , beg , end , mid ;     printf ( "Enter the element you can search in the list: \n " );     scanf ( " %d " ,& search );     beg = 0 ;     end = 9 ;     while ( beg <= end )     {         mid = ( beg + end )/ 2 ;         if ( search == list [ mid ])         {             printf ( "search successful! \n " );             break ;         }         else         {             if ( search > list [ mid...

program of linear searching a list in an array.

// it a program to search the element in an array in sequence. /* for example you can search the element in an array or list firstly you can enter the element you can search and this compare the element one by one at the starting point*/ #include <stdio.h> int main () {     int list [ 10 ]={ 12 , 5 , 4 , 6 , 7 , 9 , 10 , 2 , 8 , 0 };     int search , i ;     printf ( "Enter the element you can search in the list: \n " );     scanf ( " %d " , & search );     for ( i = 0 ; i < 10 ; i ++)     {         if ( search == list [ i ])         {             printf ( "Search successful at the position %d " , i + 1 );             break ;         }     }     if ( i == 10 )     {         printf ( "Invalid search!" );     }     return 0 ...