-
Notifications
You must be signed in to change notification settings - Fork 0
/
ex_37.cpp
54 lines (41 loc) · 928 Bytes
/
ex_37.cpp
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
47
48
49
50
51
52
53
54
// Mode calculator
//
// compile: g++ ex_37.cpp -o ex_37.out
// Ale Zuvic,
#include <iostream>
#include <stdlib.h>
#include <time.h>
using std::cout;
using std::cin;
const int SIZE = 100;
const int RANGE = 10;
int ranNumbers[SIZE];
int numbers[RANGE];
int main() {
srand(time(NULL));
for (int i=0; i<SIZE; i++) {
ranNumbers[i] = (rand() % 10) + 1;
cout << ranNumbers[i] << " ";
}
for (int i=0; i<RANGE; i++) {
numbers[i] = 0;
}
for (int i = 0; i < SIZE; i++) {
numbers [ranNumbers[i]-1] ++;
}
cout<<"\n\n";
for (int i=0; i<RANGE; i++) {
cout << "Number " << i+1 << ": " << numbers[i] << "\n";
}
int highest = numbers[0];
int highPos = 0;
for (int i = 1; i<RANGE; i++) {
if (numbers[i] > highest) {
highest = numbers[i];
highPos = i;
}
}
cout << "\nThe mode (most repeated) number is: " << highPos+1 << ", whith " << numbers[highPos] << " repetitions";
cout<<"\n";
return 0;
}