Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace Practice
- {
- class Program
- {
- static void Main(string[] args)
- {
- Random rnd = new Random();
- int common = 0, rare = 0, random, smallest = 0, biggest = 0;
- Console.WriteLine("Specify array length:");
- int length = int.Parse(Console.ReadLine());
- int[] arr = new int[length];
- int[] frequency = new int[length];
- for (int i = 0; i < arr.Length; i++)
- {
- random = rnd.Next(0, 10);
- arr[i] = random;
- }
- for (int i = 0; i < frequency.Length; i++)
- {
- frequency[i] = 1;
- for (int a = 0; a < arr.Length; a++)
- {
- if (arr[i] == arr[a])
- frequency[i]++;
- }
- }
- for (int i = 0; i < frequency.Length; i++)
- {
- if (i == 0)
- {
- smallest = frequency[i];
- biggest = frequency[i];
- }
- else
- {
- if (frequency[i] > biggest)
- biggest = frequency[i];
- if (frequency[i] < smallest)
- smallest = frequency[i];
- }
- }
- common = Array.IndexOf(frequency, biggest);
- rare = Array.IndexOf(frequency, smallest);
- Console.WriteLine("Common: {0}\nRare: {1}", arr[common], arr[rare]);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement