Sample


SUBMITTED BY: Hemraj4545

DATE: May 27, 2017, 3:39 p.m.

FORMAT: Text only

SIZE: 605 Bytes

HITS: 495

  1. #include<iostream.h>
  2. int Lsearch(int [ ],int ,int );
  3. int main( )
  4. {
  5. int AR[50],ITEM,N,INDEX;
  6. cout<<”Enter the desired array size(max. 50)”<<endl;
  7. cin>>N;
  8. cout<<”Enter Array elements”<<endl;
  9. for(int i=0;i<N;i++)
  10. {
  11. cin>>AR[i];
  12. }
  13. cout<<”Enter the element to be searched”<<endl;
  14. cin>>ITEM;
  15. index=Lsearch(AR,N,ITEM);
  16. if(index==-1)
  17. cout<<”Sorry!! Given element could not be found”<<endl;
  18. else
  19. cout<<”Element found at index:”<<index<<”,Position:”<<index+1<<endl;
  20. return 0;
  21. }
  22. int Lsearch(int AR[ ],int size,int item)
  23. {
  24. for(int i=0;i<size;i++)
  25. {
  26. if(AR[i]==item)
  27. return i;
  28. }
  29. return -1;
  30. }

comments powered by Disqus