C#C
C#2y ago
bar3l

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];
                }
            }
        }
    }
}
Was this page helpful?