Untitled

mail@pastecode.io avatar
unknown
plain_text
16 days ago
770 B
2
Indexable
Never
#include <iostream>
using namespace std;

void kerkim_binar(int arr[],int madhesia,int target)
{
    bool u_gjet=false;
    int left=0;
    int right=madhesia-1;
    while(left<=right){
     int mid = left +(right-left)/2;
      if(arr[mid]==target)
      {
          cout<<"Elementi u gjet ne kufizen e "<<mid<<endl;
          u_gjet=true;
          break;
      }
      if(arr[mid]<target)
          left = mid+1;
      else
          right = mid-1;
      }
      if(u_gjet==false)
         cout<<"Elementi nuk u gjend ne vektor !"<<endl;
}
int main() {
    int numrat[11]={1,5,7,11,15,21,15,29,35,42,48};
    cout<<"Numrat e renditur jane :"<<endl;
    for(int i=0; i<11; i++)
    {
        cout<<numrat[i]<<" ";
    }
     kerkim_binar(numrat,11,7);
    return 0;
}
Leave a Comment