Saturday, 14 January 2017

How to find a number in an Array?

#include<iostream>
using namespace std;
int main ()
{
int arr[5]={55,66,77,98,12};
int n,location=-1;
        cout<<"Enter a number to check whether it is in the array or not: ";
cin>>n;
for(int i=0;i<5;i++)
{
if(arr[i]==n)
{
location=i;
cout<<"The number you entered is in the Array...!!!"<<endl<<arr[location];
break;
}
}
if(location==-1)
{
cout<<"NOT FOUND";
}
}

No comments:

Post a Comment