Pages

Men

rh

6/10/2012

Finding Maximum and Minimum numbers from the Array


Protected void FindMaxAndMinNumber()
{
     var Numbers = new double[10];
var Minimum = 0D;
var Maximum = 0D;
Numbers[0] = 4478.72;
Numbers[1] = 67.97;
Numbers[2] = 2.32;
Numbers[3] = 13004.05;
Numbers[4] = 0.44;
Numbers[5] = 873846.08;
Numbers[6] = 120.12;
Numbers[7] = 479.23;
Numbers[8] = 12.42;
Numbers[9] = 873846.04;

Minimum = Numbers[0];

for (var i = 0; i < Numbers.Length; i++)
{
    Console.WriteLine("Number {0,2}:{1, 10}", i + 1, Numbers[i]);
}
for (var i = 0; i < Numbers.Length; i++)
         {
        if (Minimum > Numbers[i])
        Minimum = Numbers[i];
     }
    
         Console.WriteLine();
            //Console.WriteLine("Minimum = {0}", Minimum);
            label1.Text = "Minumum Number is" + Minimum;

            for (int i = 0; i < Numbers.Length; i++)
            {
                if (Maximum < Numbers[i])
                    Maximum = Numbers[i];
            }
}
           
    

No comments :

Post a Comment