Advertisement
Guest User

Untitled

a guest
Nov 21st, 2020
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.09 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4.     printf("Massivin Uzunlugunu Qeyd Edin:");
  5.     int size_of_array;
  6.     scanf("%d",&size_of_array);
  7.     int array[size_of_array];
  8.     printf("Massivin indekslerine elementleri oturun");
  9.     int index;
  10.     for(index=0;index<size_of_array;index++)
  11.     {
  12.         scanf("%d",&array[index]);
  13.     }
  14.     printf("Axtarmaq istediyiniz ededi daxil edin:");
  15.     int search_data;
  16.     scanf("%d",&search_data);
  17.     int left=0,right=size_of_array-1,mid,position=-1;
  18.     while(left<=right)
  19.     {
  20.         mid=(left+right)/2;
  21.         if(array[mid]==search_data)
  22.         {
  23.             position=mid;
  24.             break;
  25.         }
  26.         else if(array[mid]<search_data)
  27.         {
  28.             left=mid+1;
  29.         }
  30.         else if(search_data<array[mid])
  31.         {
  32.             right=mid-1;
  33.         }
  34.     }
  35.     if(array[position]==search_data)
  36.     {
  37.         printf("Axtarmaq istediyiniz eded budur %d ve bu indeksde yerlesir: %d",array[position],position);
  38.     }
  39.     else
  40.     {
  41.         printf("Axtarmaq istediyiniz eded tapilmadi:");
  42.     }
  43.  
  44.     return 0;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement