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
Given that String[] str has been initialized, to get a copy of str[0] with all characters converted to upper case, use the follo
Strike441 [17]

Answer: str[0].toUpperCase();

Explanation:

str[0] is pointing to the first character of the entire string and the code str[0].toUpperCase() will convert the characters to upper case if they are in lowercase and will remain unchanged if they are already in upper case.

7 0
3 years ago
The text discusses three approaches to combining overall cost leadership and differentiation competitive advantages. Which of th
dedylja [7]

Answer:

C. deriving benefits from highly focused and high technology markets

Explanation:

Firms that engage in cost-leadership approach seek to combine a low per-unit income with large sales for profit making purposes. Typically, but not always, they are more inclined to market their products and services to a large population base or a niche with a high demand volume. While differentiation enables a company to accomplish a competitive advantage. A Competitive advantage enables a company to achieve more strides over other companies offering related product substitutes. It is an important marketing process that is of critical economic importance to a business.

It should be noted that deriving benefits from highly focused and high technology markets is not part of the approaches to combining overall cost leadership and differentiation competitive advantages.

3 0
3 years ago
Rick is pursuing an undergraduate degree in electronics engineering. He aspires to be a robotics software engineer. Which topic
weeeeeb [17]

Options:

A.  database programming

B.  Embedded C

C.  testing software

D.  ABET

Answer:

<u>B.  Embedded C</u>

Explanation:

<em>Remember,</em> many robotic systems  make use of embedded systems, and one important programming language used is the C (Embedded C) Programming language.

Hence, since many hardware components can be programmed using C, it would therefore be necessary for Rick to be aware of Embedded C.

4 0
3 years ago
Which were important characteristics of Sparta's government? Select the two correct answers. A. Oligarchs were able to hold a lo
Cerrena [4.2K]

Answer:

Sparta's government was a combination of a monarchy, a democracy, and an oligarchy. and oligarchs were able to hold a lot of power in government.

Explanation:

Spartans government loved to have power more than anyone in their century.

4 0
3 years ago
Read 2 more answers
Helppppp ASAPPPP!!!!
Kobotan [32]

Answer:

I think it might be archive the less used data

Explanation:

archive doesnt mean delete but it does put away whatever you dont want to look at, so she still has all of the data with more space.

5 0
3 years ago
Other questions:
  • HELP PLEASE
    7·2 answers
  • Check My Work _____ are made in response to situations that have occurred frequently enough to enable managers to develop decisi
    15·1 answer
  • Which of the following refers to a feature of wikis that allows the restoring of earlier work in the event of a posting error, i
    9·1 answer
  • Examples of sound effects that can be used in video games and a cartoon
    8·1 answer
  • Different organizations implement different Information Systems base on their core business operations. explain
    14·1 answer
  • Select the term below which is a protocol that provides a method for software components to communicate, interact, and share dat
    6·1 answer
  • When a Python program is reading a file, the data is input as plain ASCII characters in a string. What is the following code doi
    15·1 answer
  • 10 POINTS
    5·1 answer
  • Since the 1960s, there have been five major generations, or cycles, of computing. Which represents those generations in order?
    15·1 answer
  • This exercise shows why each pivot (in eli1nination by pivoting) must be in a different row. (a) In Example 7, make the third pi
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!