Advertisement
shabbyheart

Untitled

Apr 7th, 2019
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define mx 5
  4. int search(int arr[],int x)
  5. {
  6. int i;
  7. for (i = 0; i < mx; i++)
  8. if (arr[i] == x)
  9. return i;
  10. return -1;
  11. }
  12. int main()
  13. {
  14. int arr[mx];
  15. for(int i=0;i<mx;i++)
  16. {
  17. cin>>arr[i];
  18. }
  19. int x;
  20. cout<<"Which Value you want to find"<<endl;
  21. cin>>x;
  22. int result=search(arr,x);
  23. if(result==-1)
  24. cout<<"Element is not present in array";
  25. else
  26. cout<<"Element is present at index"<<result;
  27. return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement