COMP2113
COMP2113_ENGG1340 Programming technologies and Computer programming II [Section 2BC] [2023]
Loading...
Searching...
No Matches
mode.cpp
Go to the documentation of this file.
1
#include <iostream>
2
using namespace
std;
3
4
int
main
(){
5
int
input;
6
cin >> input;
7
int
* set =
new
int
[input];
8
for
(
int
i = 0; i < input; i++) {
9
cin >> set[i];
10
}
11
12
int
num1 = set[0];
13
int
count1 = 1;
14
for
(
int
i = 0; i < input; i++) {
15
int
num2 = set[i];
16
int
count2 = 0;
17
for
(
int
i = 0; i < input; i++) {
18
if
(set[i] == num2) {
19
count2++;
20
}
21
}
22
if
(count2 > count1) {
23
count1 = count2;
24
num1 = num2;
25
}
26
}
27
cout <<
"The mode of the set is "
<< num1;
28
delete
[] set;
29
30
}
main
int main()
Definition
mode.cpp:4
Module8
mode.cpp
Generated on Sun Sep 29 2024 16:39:53 for COMP2113 by
1.12.0