Linear Search-C++

 #include<iostream.h>  
 #include<conio.h>  
 class linear( )  
 {  
      private:  
           int i, m, a[10], n, t;  
      public:   
           void get( );  
           void search( );  
 };  
 void linear :: get( )  
 {  
      cout<<”\nEnter the limit : “;  
      cin>>n;  
      cout<<”\nEnter the elements : “;  
      for(i=0; i<n ; i++)  
           cin>>a[i];  
 }  
 void linear :: serach( )  
 {  
      cout<<”\nEnter the element to be serached : “;  
      cin>>m;  
      for(i=0 ; i<n; i++)  
      {  
           if(a[i]==m)  
           {  
                t=1;  
                break;  
           }  
      }  
      if(t==1)  
            cout<<”\nElement is found”;  
      else  
           cout<<”\nElement is not found”;  
 }  
 void main( )  
 {  
      clrscr( );  
      linear l;  
      l.get( );  
      l.search( );  
      getch( );  
 }  

Share This!


No comments:

Post a Comment

Code Of The day - Suggest An Output For The Snippet

  #include<stdio.h>   
  int main()   
  {   
   float a=3.15529;   
   printf("%2.1f\n", a);   
   return 0;   
  }   
· A Code Archive - code1archive