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
A range in which a measuring instrument or controller does not respond is the
cricket20 [7]

Answer:

Dead band

Explanation:

In Instrumentation, dead band is defined as a range in which a measuring instrument or controller does not respond. It is also known as the neutral zone or dead zone and it is usually caused by packing friction or unbalanced forces.

4 0
3 years ago
What is printed to the console?<br> console.log(15 % 4);<br><br> 1<br><br> 2<br><br> 3<br><br> 4
Radda [10]

Answer:

3

Explanation:

7 0
2 years ago
Write a Python program that inputs an integer between 0 and 1000 and adds all the digits in the integer. For example, if integer
nignag [31]

I've included my code in the picture below.

5 0
3 years ago
Which type of link is normally used to interconnect two peripheral modules (pm) in the digital multiplex system (dms)?
natta225 [31]

The answer is DS-30A. The Roland DS30A is a 24-bit Digital Reference Monitor which can add pristine 24-bit/96kHz. They are small speakers.

4 0
3 years ago
What are the characteristics of:<br> Master file<br> Transaction file<br> Reference file
IRISSAK [1]
<h3>Master File :-</h3>
  • Master files contain descriptive data, such as name and address, as well as summary information, such as amount due and year-to-date sales.

<h3>Transaction File :-</h3>
  • Fast performance with a rapid response is critical. Organisations rely heavily on their TPS with failure possibly stopping business.

<h3>Reference File :-</h3>
  • Information in one drawing can be overlaid on a different drawing, eliminating the need to redraw information.
  • Proper use of reference files will result in significant time savings and greater coordination of drawings.

Explanation:

<h3>Hope it helps you!</h3>
7 0
2 years ago
Other questions:
  • In a case where electrical current leakage from the circuit occurs,
    7·2 answers
  • Data mining is ______? a process of finding meaningful patterns in data to improve decisions a strategy for locating security so
    7·1 answer
  • 18 Select the correct answer.
    5·1 answer
  • Which file type is typically used for videos? GIF MPEG MP3 PDF
    8·1 answer
  • Where is the typical location of a touchpad inside of a laptop?
    13·1 answer
  • 11.
    9·2 answers
  • ​________________________ are the main forms of direct and digital marketing. A. Mobile​ marketing, social media​ marketing, and
    5·1 answer
  • Last bittttt of points
    8·1 answer
  • PLS HELP ME!! WILL GIVE BRAINLIEST
    7·2 answers
  • Paragraph on uses of computer 100 words plss​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!