Skip to content

Instantly share code, notes, and snippets.

@m-ahmedy
Created May 19, 2017 15:26
Show Gist options
  • Save m-ahmedy/9f91c571013068509b9696e64f4116e6 to your computer and use it in GitHub Desktop.
Save m-ahmedy/9f91c571013068509b9696e64f4116e6 to your computer and use it in GitHub Desktop.
Find value in array elements.
#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