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
Really desperate!
bija089 [108]

Answer: Sorry to break this to you but you can't.

Explanation:

7 0
3 years ago
Read 2 more answers
What action should you take when using removable media in a scif?
inysia [295]

Explanation:

What actions should you take when printing classified material within a Sensitive Compartmented Information Facility (SCIF)? Retrieve classified documents promptly from printers.

7 0
3 years ago
Enterprise software is designed for organizations to __________.
klemol [59]

Answer:

The goal of enterprise software is to enable the activities of large organizations, supporting a wide range of different user roles.

6 0
2 years ago
Human services organizations seek to make changes and help people in need to improve their .
bixtya [17]

Answer:

quality of life

Explanation:

7 0
3 years ago
Why is the given C++ program is not working?
Jobisdone [24]

Answer:

Please find the edited program below:

#include<iostream>

#include <stdio.h>

using namespace::std;

int main()

{

char ch;

cout<<"Enter any letter: ";

ch=getchar();

if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u'|| ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U')

cout<<"Vowel";

else

cout<<"Consonant";

return 0;

}

Explanation:

We cannot input char type using cin, we need to use getchar, and it is under header file stdio.h. Also, for comparing we need to use == and not =. And corrrect way of including std is using namespace::std;

3 0
3 years ago
Other questions:
  • ________ returns the last character in a StringBuilder variable named strBuf? Select one: A. strBuf.charAt(strBuf.length() - 1)
    15·1 answer
  • Alcohol is a gateway drug. true or false?
    13·2 answers
  • Read the following scenario: A project will require more people than originally estimated. Identify the possible risks to the pr
    8·2 answers
  • T F The exit function can only be called from main .
    10·1 answer
  • Someone asks you for help with a computer that hangs at odd times. You turn it on and work for about 15 minutes, and then the co
    7·1 answer
  • What is the best way to protect against the loss of important files
    15·1 answer
  • Por favor alguem poderia me falar qual PC e melhor: Computador Gamer Fox PC FPS Intel Core i5 8GB (GeForce GTX 1050Ti 4GB GDDR5)
    15·1 answer
  • One of your start-ups uses error-correcting codes, which can recover the original message as long as at least 1000 packets are r
    8·1 answer
  • How could the company benefit by applying Agile principles?
    5·2 answers
  • Fwee Pwoints Fwor You
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!