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]
4 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]4 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
hi friends I got the answer down load tutu app from chrome then from tutu app we can download any rare games for ex. Pokemon sun
svlad2 [7]

Answer: Cool!

Explanation: That's sounds amazing!^^

7 0
4 years ago
A series of events that gets the computer ready for work is known as what?
DedPeter [7]
I think the answer is the third one...
7 0
4 years ago
Read 2 more answers
Explain why binary codes are used to represent characters, numbers and symbols :)
guajiro [1.7K]
Binary (base 2) is much easier to encode on a hard drive as it only has two states, whereas letters, numbers and symbols can be one of hundreds.
8 0
3 years ago
Read 2 more answers
Name the technique used to separate the mixture of colours in black ink ​
Nitella [24]

Answer:

chromatography

hope it helps

6 0
3 years ago
Read 2 more answers
A computer that delivers requested web pages to your computer or mobile device is a(n) _____.
yaroslaw [1]

Answer:

Web Server

A web server is server software, or hardware dedicated to running this software, that can satisfy client requests on the World Wide Web. A web server can, in general, contain one or more websites. A web server processes incoming network requests over HTTP and several other related protocols.

6 0
4 years ago
Other questions:
  • Why did LISD had to block the game “among us”?
    8·2 answers
  • Need Help !!! Please
    8·1 answer
  • Which of the following statements is correct? A. The columns will be listed in the results in the same order they are stored in
    7·1 answer
  • Below is the prototype for a function that takes two pointers to integer variables as its parameters. The purpose of the functio
    14·1 answer
  • 6 external parts of computer
    10·2 answers
  • (a) Define a goal for software product quality and an associated metric for that attribute. (b) Explain how you could show that
    7·1 answer
  • Why do we use antivirus program?<br><br>please tell fast​
    12·1 answer
  • List an example of application software used in spreadsheet​
    11·2 answers
  • Add definitions for the following keywords to your glossary of words.
    6·1 answer
  • Accenture is one of several hundred companies that has signed on to the united nations global compact (ungc) business ambition p
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!