Problem working on a GNU Compiler....plss help

Discussion in 'C++' started by imported_Anmol, Aug 29, 2010.

  1. imported_Anmol

    imported_Anmol New Member

    Joined:
    Jun 28, 2010
    Messages:
    6
    Likes Received:
    0
    Trophy Points:
    0
    Hey everyone,:)
    I am used to working on turbo c++....and i thus know nothing about coding in gnu compilers...

    Please help me on the following program (binary search for k nos. in an array of n nos.) i have written on DEV++....I am not able to see the output.(i checked the output screen also and final result screen also....)..Please Help....

    //BINAR SEARCH FOR 'K' NOS. IN A SORTED ARRAY OF 'N' ELEMENTS.

    Code:
    #include<iostream>
    using namespace std;
    
    int main()
    {
        int n,j,k,a[50],b[50],i,beg,end,mid;     
        int p=0;                
    
     cout<<"enter the no. of elements in the array ";
     cin>>n;
     
     cout<<"enter the no. of elements  to be  searched in the array ";
     cin>>k;
    
     cout<<"enter the elements : ";
     for (i=0;i<n;i++)
     cin>>a[i];
    
     cout<<"enter nos. to be searched ";
     for (j=0;j<k;j++)
     cin>>b[i];
     
     i=0;
     while(i<k)
     {
      beg =0;
      end = n-1;
      p=0;
    
      while (beg<=end)
       {
        mid= (beg + end) /2;
        if (b[i]==a[mid])
          {
           p=1;
           break;
          }
          else if(b[i] > a[mid])
    	 beg = mid + 1;
           else
    	end = mid - 1;
       }
      i++;
    
      if (p==0)
        cout<<" N ";
       else
        cout<<" Y ";
    
     }
    
     system("pause");          
         
         
     return 0;
    
    }
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice