In: Computer Science
Write a program that allows the user to search the array to find the number entered
main.cpp
/* program that allows the user to search the array to find the number entered */
#include <iostream>
using namespace std;
int main()
{
int array[100], search, c, n;
cout<<"Enter the number of elements in
array"<<endl;
cin>>n;
cout<<"Enter "<<n<<" integer(s)
"<<endl;
for (c = 0; c < n; c++)
cin>>array[c];
cout<<"Enter the number to
search"<<endl;
cin>>search;
for (c = 0; c < n; c++)
{
if (array[c] ==
search) /* if required element found
*/
{
cout<<search<<" is present at location "<<
c+1<<endl;
break;
}
}
if (c == n)
cout<<search<<" is not
present in array"<<endl;
return 0;
}
Output:-
Enter the number of elements in array 5 Enter 5 integer(s) 10 20 30 40 50 Enter the number to search 40 40 is present at location 4