Integer to find the first and second maximum in array in c#

          Maximum in array in c# (console application)
     
           int [] numbers = { 6, 3, 37, 12, 46, 5, 64, 21 };
            int highest = 0;
            int second_highest = 0;
            foreach (int n in numbers)
            {
                if(highest<n)
                {
                    highest = second_highest;
                    highest = n;
                }
              
                
                else if(second_highest<n)
                {
                    second_highest = n;
                }
                
            }
            Console.WriteLine("First Max Number: " + highest);
            Console.WriteLine("Second Max Number: " + second_highest);
            Console.ReadKey();

Comments

Popular posts from this blog

my reframce

Angular UI Grid To Bind JSON Data