Advertisement
Martichka

Arrays/ Task - 9 Frequent Number

Jan 12th, 2013
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.92 KB | None | 0 0
  1. using System;
  2. class FrequentNumber
  3. {
  4.     static void Main()
  5.     {
  6.         int[] equalNum = { 4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3 };
  7.         int[] counter=new int[equalNum.Length];
  8.         int secondCounter = 0;
  9.         int frequentNum = 0;
  10.         for (int index = 0; index < equalNum.Length-1; index++)
  11.         {
  12.             counter[index] = 1;
  13.             for (int check = 1; check < equalNum.Length; check++)
  14.             {
  15.                 if(equalNum[index] == equalNum[check])
  16.                 {
  17.                     counter[index] += 1;
  18.                    
  19.                 }
  20.                 if (counter[index] > secondCounter)
  21.                 {
  22.                     secondCounter = counter[index];
  23.                     frequentNum = equalNum[index];
  24.                 }
  25.             }
  26.         }
  27.         Array.Sort(counter);
  28.         Console.WriteLine(counter[counter.Length-1]+ " "+ frequentNum);
  29.        
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement