Advertisement
dimov

Untitled

Jan 6th, 2013
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2.  
  3. class FrequentNumbers
  4. {
  5.     static void Main()
  6.     {
  7.         int[] array1 = new int[13] { 4, 1, 1, 4, 2, 3, 4, 4, 1, 2, 4, 9, 3 };
  8.  
  9.         for (int i = 0; i < array1.Length-1; i++)
  10.         {
  11.             for (int j = i+1; j < array1.Length; j++)
  12.             {
  13.                 if (array1[i]>=array1[j])
  14.                 {
  15.                     int a = array1[i];
  16.                     array1[i] = array1[j];
  17.                     array1[j] = a;                  
  18.                 }
  19.             }
  20.         }
  21.         int counter = 0;
  22.         int bigCounter = 0;
  23.         int whatNum = 0;
  24.         for (int i = 0; i < array1.Length-1; i++)
  25.         {
  26.             if (array1[i] == array1[i + 1])
  27.             {
  28.                 counter++;
  29.                 if (bigCounter <= counter)
  30.                 {
  31.                     bigCounter = counter;
  32.                     whatNum = array1[i];
  33.                 }
  34.             }
  35.             else
  36.             {
  37.                 counter = 0;
  38.             }
  39.         }
  40.         Console.WriteLine("We have {0} members of the number \"{1}\" in the array",bigCounter+1, whatNum);
  41.     }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement