1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Sedaia [141]
3 years ago
10

Create a method to search an un-ordered array of integers for a value, if the value is found return the index of its position in

the array, if not found, return -1.
Computers and Technology
1 answer:
Hatshy [7]3 years ago
6 0

Answer:

Following are the program in C++ language  

#include <iostream> // header file

using namespace std; // namespace

int search(int s[],int s1,int n) // function search  

{

   for (int k= 0; k<n; k++) // iterating over the loop

 {

   if (s[k] == s1)   // searching the element  

   {

   return(k); // return the index

     break;

   }

 

}

return(-1); // return(-1)

}

int main() // main function

{

int arr[100],n1,i,s; // variable declaration  

cout<<"Enter number you want in the array:";

cin>>n1;

cout<<"Enter the elements in the array\n ";

for (i = 0; i<n1; i++)

{

   cin>>arr[i]; // taking input into the array  

}

 cout<<"Enter a number you want to search: ";

cin>>s; // read the serach element by the user  

int res= search(arr,s,n1); // calling function search

cout<<res; // display result

 return 0;

}

Output:

Enter number you want in the array:3

Enter the elements in the array

1

2

34

Enter a number you want to search: 2

2

Explanation:

Following are the description of the program  

  • Read the number you want in array in the "n1" variable of int type.
  • Read the array by the user in the "arr ".
  • Read the searching element in the  "s" variable.
  • calling the function search by passing array arr, searching element "s" and "n1".
  • In the search function, it returns the index of its position in the array, if not found then it return -1.
  • Finally print the index.  

You might be interested in
What are different sheet icons
telo118 [61]

Answer:

There are three types of icons: “universal,” “conflicting” and unique icons.Explanation:

3 0
3 years ago
A. True <br><br> b. False: most modern computers can understand and execute pseudocode.
Veronika [31]
False






---------------------------------------------
7 0
3 years ago
Routing and remote access services allow users to connect to private networks using or:.
Luda [366]

Answer:

Users can connect to a remote access server through a dial-up connection or a virtual private network (VPN) connection.

Explanation:

A dial-up connection requires both the server and the client computer to have a correctly configured modem. The client and the server connect over analog public telephone networks. To enhance the security of a dial-up connection, use data encryption, Windows logon and domain security, remote access policies and callback security.

8 0
2 years ago
In what decade did the Internet begin to be used widely by the public and not just government entities?
ICE Princess25 [194]
I think 1980s, not 100% sure
7 0
4 years ago
Read 2 more answers
What should you do to organize a large amount of data??
Kay [80]
Set them up from least to greatest or create a number graph with all the data.
5 0
3 years ago
Other questions:
  • Type the correct answer in the box. Spell the word correctly.
    14·2 answers
  • Edmund wants to visit his university's website. Which software application would he use?
    14·1 answer
  • Which term is used to describe bitmap images
    8·2 answers
  • How to study program ?
    11·1 answer
  • Let's practice Audience analysis by going to the Google Merchandise Store demo account with a date range of Feb 1, 2016 - Feb 29
    13·1 answer
  • Write a program that declares an array named myArray with 8 components of the type int. Initialize the array to 8 values that th
    6·1 answer
  • Which word or phrase refers to an increasingly common method of computing and storing files?
    15·2 answers
  • Parameters and return make
    10·1 answer
  • HC - AL-Career Preparedness
    8·1 answer
  • Joining a computer to active directory involves joining the computer to a workgroup. True or false.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!