Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
unsorted array which has a number in the majority (a number appears more than 50% in the array
//Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { //Your code goes here int [] x = {1,2,3,4,5,2,2,2,2}; int Majority = 0; int number, count; number = count = 0; for(int i = 0; i <= x.Length; i++) { for(int j = i; j < x.Length; j++) { if(x[i] == x[j]) { count++; } } if(count > x.Length /2) { Majority = count; number = x[i]; count = 0; } count = 0; } Console.WriteLine("No. "+ number + " comes "+ Majority); } } }
run
|
edit
|
history
|
help
0
Collection Basic
interface
іфи
Program
Lottery
12
a6
select z kolekcji w kolekcji (np. dokumenty i pizycje)
Main5.1
shut down