Alonuis
Alonuis
CC#
Created by Alonuis on 8/4/2024 in #help
question for those reading this:
do you guys have a job as a programmer? or you're just doing this as a hobby or someth
3 replies
CC#
Created by Alonuis on 7/25/2024 in #help
can anyone help? i need to print out the 3 most repeated numbers in the array
int[] arr = { 5, 2, 8, 4, 0, 6, 11, 8, 9, 11, 2, 11 };
int mostrepeat = -999;
int cnt = 0;
int maxcnt = 0;
for (int main = 0; main < 3; main++)
{
if (mostrepeat != -999)
{
Console.WriteLine(mostrepeat);
cnt = 0;
maxcnt = 0;
}


for (int i = 0; i < arr.Length; i++)
{
if (arr[i] == mostrepeat)
continue;

for (int j = i; j < arr.Length; j++)
{
if (arr[j] == arr[i])
{
cnt++;
if (cnt > maxcnt)
{
maxcnt = cnt;
mostrepeat = arr[i];
}
}
}
}
}
int[] arr = { 5, 2, 8, 4, 0, 6, 11, 8, 9, 11, 2, 11 };
int mostrepeat = -999;
int cnt = 0;
int maxcnt = 0;
for (int main = 0; main < 3; main++)
{
if (mostrepeat != -999)
{
Console.WriteLine(mostrepeat);
cnt = 0;
maxcnt = 0;
}


for (int i = 0; i < arr.Length; i++)
{
if (arr[i] == mostrepeat)
continue;

for (int j = i; j < arr.Length; j++)
{
if (arr[j] == arr[i])
{
cnt++;
if (cnt > maxcnt)
{
maxcnt = cnt;
mostrepeat = arr[i];
}
}
}
}
}
43 replies