Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program that stores numbers from the range 0 - 1000 in an array. Your pr

ID: 3673425 • Letter: W

Question

Write a program that stores numbers from the range 0 - 1000 in an array. Your program should create an array of size 20 store random numbers into the array ask the user for a number call the following function The function accepts 3 arguments - the array, the size of the array and the user number. It should then print the location (index) and the value of all numbers larger than the user's number. For testing purposes your program should ask the user if they want to run in test, or production mode. In production mode the program will fill the array with random numbers, and limit the user test number to the range 1-1000 In test it will use the numbers 1 through 20, and limit the user input to 1-20

Explanation / Answer

See this below program will read the random numbers with in the range of 1 to 1000 and will store in array
and will read the another number and will search the number and print the numbers greater than that number.

#include <iostream>
using namespace std;
#include <cstdlib>
#include <ctime>

int main ()
{
int array[20],number = 0;

/* initialize random seed: */
srand (time(NULL));

for(int i =0 ; i<20;i++)
{
   /* generate secret number between 1 and 1000: */
   array[i] = rand() % 1000 + 1;
}

cout<<"Enter Number :"<<endl;
cin>>number;
int index;
for(int i =0 ; i<20;i++)
{
   if(array[i]==number)
       index = i;
}

for(int i =0 ; i<20;i++)
{
   if(array[i]>=number)
       cout<<array[i]<< " ";
}
return 0;
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote