-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandom Search.cpp
More file actions
46 lines (45 loc) · 1000 Bytes
/
Copy pathRandom Search.cpp
File metadata and controls
46 lines (45 loc) · 1000 Bytes
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
38
39
40
41
42
43
44
45
46
//Creates array with random numbers and finds the Biggest one
void RandomBigger(int array[], const int Size = 10)
{
int a, b = 0;
//Boolen to check is new random number array or not
bool alreadyHere;
for (int i = 0; i < Size; )
{
alreadyHere = false;
//creates new random number
int NewR = rand() % 20;
for (int j = 0; j < i; j++)
{
if (array[j] == NewR)
{
alreadyHere = true;
break;
}
}
//IF this new random number is not in array than it is added to array
if (!alreadyHere)
{
array[i] = NewR;
i++;
}
}
for (int t = 0; t < Size; t++)
{
a = t + 1;
//Searchs array to the biggest number
if (array[t] < array[a])
b = array[a];
cout << array[t] << endl;
}
cout << "\nBiggest number: " << b << endl;
}
int main()
{
//Function sets timer to NULL to get REAL random numbers without repeating
srand(time(NULL));
const int Size = 10;
int array[Size];
RandomBigger(array, Size);
return 0;
};