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
jonny [76]
3 years ago
12

Write a program in c++ that asks the user for a sequence of n​integers, where the user provides the number of elements n​ then e

ach of the elements. After storing the n​ values in the array, ask the user for a value to search within those elements and return the index of the first instance (starting with 0 as the first element). Each integer should be stored in an array in the order they were read from the user. Follow the prompts and output format listed below. The user is expected to enter no more than 256 elements, the array should be able to hold no less and no more​ than 256.
Computers and Technology
1 answer:
timurjin [86]3 years ago
8 0

Answer:

// here is code in C++.

#include <bits/stdc++.h>

using namespace std;

// function that return the first occurrence of item

int fun(int a[],int item,int n)

{

   for(int y=0;y<n;y++)

{// find first occurance

   if(a[y]==item)

   // return index

   return y;

}

}

// main function

int main()

{

// variables

int n,item;

// array that holds 256 number only

int a[256];

cout<<"enter the value of n:";

//read the value of n

cin>>n;

// if n is greater than 256, it will again ask for input

while(n>256)

{

   cout<<"value of n should be less than 256:"<<endl;

   cout<<"enter value of n again:";

   cin>>n;

}

// read n numbers

cout<<"enter "<<n<<" numbers:";

for(int x=0;x<n;x++)

{

   cin>>a[x];

}

// read item to be searched

cout<<"enter the number to be searched:";

cin>>item;

// calling the function and print the index

cout<<"item found at index "<<fun(a,item,n)<<endl;

}

Explanation:

Declare a variable "n" and create an array of size 256.Then read the value of "n". If n is greater than 256 then it will again ask user to enter a number less than 256.Then it will read "n" numbers from user and store them into array.Then it will read item to be searched and call the function with parameter array, item and n. function will find the first occurrence of the item and return its index.

Output:

enter the value of n:280

value of n should be less than 256:

enter value of n again:7

enter 7 numbers:12 4 7 9 7 6 21

enter the number to be searched:7

item found at index 2

You might be interested in
Why is it a good idea to view your HTML code in more than one web browser
Mandarinka [93]

Because some features may not be available on some browsers. By viewing it on different browsers, we can see if there's any incompatibilities and fix them.

5 0
3 years ago
Which media device uses the characteristic continuous?
notka56 [123]
The media device that uses characteristics continuous is the Screen.
In Continous characteristic 
is where there is timing relationship between source and destination.
4 0
3 years ago
How do i do a mutioutput on a mac
Tcecarenko [31]
Here's what I found

To use an aggregate device with Logic:
Open Logic Pro or Logic Express.
Choose Logic Pro > Preferences > Audio or Logic Express > Preferences > Audio and select the Devices tab.
Select the Output Device drop-down menu and choose the aggregate device from the list. ...
Click Apply Changes at the bottom-right of the window.
4 0
3 years ago
Select all that apply. To select more than one worksheet at the same time, which of the following keys on your keyboard can you
Colt1911 [192]
<em>Shift </em>selects multiple worksheets at the same time. <em>Ctrl</em> selects all that you selected with Ctrl pressed.
4 0
3 years ago
Computer are most wonderful creation of 21st century how ?​
son4ous [18]

Answer:

It can do all the functions at a speedy rate and also helps us to search and progress in our homes and businesses. A computer can therefore be called a calculator with a twist for not only does it perform fast calculations, but it also has other special characteristics.

Explanation:

hope it helps you

6 0
1 year ago
Other questions:
  • A department store plans to upgrade its IT infrastructure to support a new order-processing application with rich features. The
    13·1 answer
  • What kind of energy transformation occurs in a gasoline-powered car?
    14·1 answer
  • What items do you keep in a data base
    5·1 answer
  • I wanna start answering questions for people, but I don't quite know how. Can you help me?​
    13·1 answer
  • bro this scared me, i thought i just got hacked, could someone explain why when i went to ask a question, it kicked me out my ac
    9·2 answers
  • You’re having trouble connecting to the Internet so you call your Internet service provider for help. They need to know the perm
    15·1 answer
  • Given that n refers to a positive int use a while loop to compute the sum of the cubes of the first n counting numbers, and asso
    12·1 answer
  • What is the meaning of FTTH
    9·2 answers
  • How is technology moving the business world forward?
    13·1 answer
  • 23. Convert the following to Megabytes<br> a) 2GB<br> b) 2056 Bytes-
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!