Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main()
- {
- printf("Massivin Uzunlugunu Qeyd Edin:");
- int size_of_array;
- scanf("%d",&size_of_array);
- int array[size_of_array];
- printf("Massivin indekslerine elementleri oturun");
- int index;
- for(index=0;index<size_of_array;index++)
- {
- scanf("%d",&array[index]);
- }
- printf("Axtarmaq istediyiniz ededi daxil edin:");
- int search_data;
- scanf("%d",&search_data);
- int left=0,right=size_of_array-1,mid,position=-1;
- while(left<=right)
- {
- mid=(left+right)/2;
- if(array[mid]==search_data)
- {
- position=mid;
- break;
- }
- else if(array[mid]<search_data)
- {
- left=mid+1;
- }
- else if(search_data<array[mid])
- {
- right=mid-1;
- }
- }
- if(array[position]==search_data)
- {
- printf("Axtarmaq istediyiniz eded budur %d ve bu indeksde yerlesir: %d",array[position],position);
- }
- else
- {
- printf("Axtarmaq istediyiniz eded tapilmadi:");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement