Created
May 19, 2017 15:26
-
-
Save m-ahmedy/9f91c571013068509b9696e64f4116e6 to your computer and use it in GitHub Desktop.
Find value in array elements.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
int main() | |
{ | |
int arrSize, value; | |
bool found=false ; | |
cout<<"Enter array size: "; | |
cin>>arrSize; | |
int arr[arrSize]; | |
for(int i=0 ; i<arrSize ; i++) | |
{ | |
cout<<"Enter value #"<<i+1<<" : "; | |
cin>>arr[i]; | |
} | |
cout<<"\n\n"; | |
cout<<"Enter search value: "; | |
cin>>value; | |
cout<<"\n"; | |
for(int i=0 ; i<arrSize ; i++) | |
{ | |
if(arr[i]==value) | |
{ | |
found=true; | |
cout<<"Value "<<value<<" is at index #"<<i+1<<endl; | |
} | |
} | |
if(!found)cout<<"Cannot find the value "<<value<<" in the array."<<endl; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment