Program


SUBMITTED BY: Hemraj4545

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

FORMAT: Text only

SIZE: 581 Bytes

HITS: 576

  1. #include<iostream.h>
  2. void Lsearch(int [ ],int,int);
  3. void main( )
  4. {
  5. int arr[50];int n;int num;
  6. cout<<"Enter the no. of elements:";
  7. cin>>n;
  8. for(int i=0;i<n;i++)
  9. {
  10. cout<<"Enter the element "<<i+1<<":"; cin>>arr[i];
  11. }
  12. cout<<"Enter the element to be searched:"; cin>>num;
  13. Lsearch(arr,n,num);
  14. }
  15. void Lsearch(int ar[],int size,int number)
  16. {
  17. int flag=0,pos;
  18. for(int i=0;i<size;i++)
  19. {
  20. if(ar[i]==number)
  21. {
  22. pos=i+1;
  23. flag=1;
  24. break;
  25. }
  26. }
  27. if(flag==1)
  28. cout<<"Element Found at position:"<<pos;
  29. else
  30. cout<<"Element not found..";
  31. }

comments powered by Disqus