Advertisement
Guest User

Untitled

a guest
May 19th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.63 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. int arrSize, value;
  8. bool found=false ;
  9.  
  10. cout<<"Enter array size: ";
  11. cin>>arrSize;
  12. int arr[arrSize];
  13.  
  14. for(int i=0 ; i<arrSize ; i++)
  15. {
  16. cout<<"Enter value #"<<i+1<<" : ";
  17. cin>>arr[i];
  18. }
  19. cout<<"\n\n";
  20.  
  21. cout<<"Enter search value: ";
  22. cin>>value;
  23. cout<<"\n";
  24.  
  25. for(int i=0 ; i<arrSize ; i++)
  26. {
  27. if(arr[i]==value)
  28. {
  29. found=true;
  30. cout<<"Value "<<value<<" is at index #"<<i+1<<endl;
  31. }
  32. }
  33.  
  34. if(!found)cout<<"Cannot find the value "<<value<<" in the array."<<endl;
  35.  
  36. return 0;
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement