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 ConsoleApplication23
- {
- class Program
- {
- static void Main(string[] args)
- {
- int size, common=0, rare=0, appearances, appearancesCommon = 1, appearancesRare = 2;
- size = int.Parse(Console.ReadLine());
- int[] arr = new int[size];
- Random rnd = new Random();
- for (int i = 0; i < arr.Length; i++) //sets up array
- {
- int randomNum = rnd.Next(0, 10);
- arr[i] = randomNum;
- }
- for (int i = 0; i < arr.Length; i++)
- {
- appearances = 0;
- for (int k = 0; k < arr.Length; k++) //counts appearances of each number
- {
- if (arr[i] == arr[k])
- {
- appearances++;
- }
- }
- if (appearances > appearancesCommon)
- {
- appearancesCommon = appearances;
- common = arr[i];
- }
- if (appearances < appearancesRare)
- {
- appearancesRare = appearances;
- rare = arr[i];
- }
- }
- Console.WriteLine("\nMost common number: {0}. Rarest number: {1}.", common, rare);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement