Write a program that allows the user to search the array to

Write a program that allows the user to search the array to find the number entered

Solution

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:-

Write a program that allows the user to search the array to find the number enteredSolutionmain.cpp /* program that allows the user to search the array to find

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site