HELP ME THIS TOPIC

Task 2:
Write a program that randomly generates two sets of integers that is, 1000 integers. Determine whether there exists an integer in the first set in such a way that its value is identical with an integer in the second set. Record how much time it will be executed. Analyze your algorithm complexity using big-o notation.
closed account (1CfG1hU5)
lots of the integers could match from each set. what is the range of integers being
generated from each set? 1-20, 1-10, are both sets same range?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <cstdlib> 
#include <ctime> // clock() and CLOCKS_PER_SEC
#include <iostream>
using namespace std;

int main() 
{ 
   clock_t start = clock();
   int y;
   int index;
   int random_integer[1000]; // increased array size to 1000, was 10
   int count = 0; // make your counter variables set to 0 to count above
                        // number was way too high when only "int count;"
                        // got this # when count was not equal to 0.  "4196874"
                        // 4 million way more than 1000 and not all randoms would = y

   cout<<"random_integer is an array of 1000 numbers\n";
   cout<<"y is the inserted number\n\n";
   cout<<"Please insert a number 1 to 10: ";
   cin >> y;
   cout << "\n";
   srand((unsigned)time(0)); 

   for(index=0; index<=999; index++) {  // reset for 1000 elements 
     random_integer[index] = rand() % 10+1; 
    if (random_integer[index] == y)
        count++;
   }

cout << "number of times random_integer = y is " << count << "\n";

clock_t stop = clock();
cout << "execution time is " << (stop-start)/double(CLOCKS_PER_SEC)*1000 << " seconds" << endl;

return 0;

}


modify this code from previous question
Last edited on
Topic archived. No new replies allowed.