Create an array that holds 1000 random integers between 1100

Create an array that holds 1000 random integers between 1-1000. Allow the user to enter an integer to search. Output the location of number if it exists in the Array. (Number could appear more than once.) or Output number does not exist in the Array.

Solution

#include <stdio.h>
#include <iostream>

void main()
{

int size,num;
boolean flag=false;
cout<< \"how big do you want the array?\" << endl;
cin >> size;

int array[size];


for(int i=0; i<size; i++){
array[i] = (rand()%1000)+1;

cout << array[i] << \" \";
}
cout<< \"enter an integer to search?\ \" ;
cin >> num;
for(int i=0; i<size; i++){
if( array[i] = =num)
{
flag=true;
cout<<\"Element found at location\"<<i+1;
}
  
}
if(flag==false)
cout<<\"element not found\";

getch();

}

Create an array that holds 1000 random integers between 1-1000. Allow the user to enter an integer to search. Output the location of number if it exists in the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site