This works perfectly...but when I use foreach instead of for this doesn't works. I can't understand for and foreach are same.
namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] array = new int[10];
            Console.WriteLine("enter the array elements to b sorted");
            for(int i=0;i<10;i++)
            {
                array[i] = Convert.ToInt32(Console.ReadLine());
            }
            int smallest = array[0];
            for(int i=0;i<10;i++)
            {
                if(array[i]<smallest)
                {
                    smallest=array[i];
                }
            }
            int largest = array[9];
            for(int i=0;i<10;i++)
            {
                if (array[i] > largest)
                {
                    largest = array[i];
                }
            }
            Console.WriteLine("the smallest no is {0}", smallest);
            Console.WriteLine("the largest no is {0}", largest);
            Console.Read();
        }
    }
}
                Why are you not using this?
int[] array = { 12, 56, 89, 65, 61, 36, 45, 23 };
int max = array.Max();
int min = array.Min();
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With