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
Jack has a fear of getting up in front of a group of people and giving a presentation. When he gave his last presentation, he ta
dezoksy [38]

Answer:

Jack has to be very calm and try his best to present himself in an outward way and think about the fact that by the end of the night no one will remember that he messed up, I feel like he'll be okay :)

7 0
3 years ago
Read 2 more answers
The first step to keeping your home safe is to minimize the overall amount of _______________ materials you store in your home.
Bingel [31]

Answer: The valuable, precious, or expensive items.

Explanation:

4 0
3 years ago
Which type of systems development is characterized by significantly speeding up the design phase and the generation of informati
nydimaria [60]

Answer:

Joint Application Development (JAD)

Explanation:

Joint Application Development is a method of application development that  lay emphasis on the up-front aspect of the application development cycle whereby steady communication between the designers and the intended users of the application under development by coming together in collaborative workshop styled discussions known as JAD sessions involving the mediators, facilitator, observers, end users, experts, and developers. As such with JAD process application development result in fewer errors high quality and is completed in lesser time.

3 0
3 years ago
How are you today? I'm fine
sweet-ann [11.9K]

Answer:

no this is partick.

Explanation:

8 0
3 years ago
Read 2 more answers
URGENT!! Ronald wants to search for an image of a sports car. Ronald doesn’t have to remember the specific name of the image to
vaieri [72.5K]

Answer:

Ronald will use a search engine

Explanation:

Ronald will use a search engine to find an image of a sports car, like he would do to search information to help him with his homeworks.

He could use keywords to identify some features he wants to see in the picture.  For example "red sports car" or "Ferrari sports car".  The results might come from a general Web spider fetch job or from specialized sites in terms of stock photos for example.

Then, Ronald will be able to see many images matching its request... and choose the one most appropriate for his needs.

5 0
3 years ago
Other questions:
  • Define the following term: - hue
    11·2 answers
  • When creating a software package, the software must be designed, the code must be written, and then the code must be tested. Thi
    6·1 answer
  • What is a fragment shader? Question 5 (3 marks) What is trilinear filtering?
    8·1 answer
  • Which of these statements is true? Steve Jobs invented the mouse as an input device. Bill Gates invented the mouse as an input d
    6·1 answer
  • You are given a data set with information from 1,000 high school students (of which the following is a part of the data) and ask
    6·1 answer
  • Write a program that determines a student's letter grade. Allow the user to enter three test scores. The maximum score on each t
    9·1 answer
  • Your textbook discussed a record store example where one user could perform a query to determine which recordings had a track le
    14·1 answer
  • What do we call data that's broken down into bits and sent through a network?
    15·1 answer
  • Truth or dare????????????
    5·1 answer
  • What are the features of a computer speaker​
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!