A4 Write a program to find the smallest number and its position in an array

    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[5];
            int Small, Position = 0;

            Console.WriteLine("Enter 5 Numbers : ");
            for (int i = 0; i < a.Length; i++)
                a[i] = int.Parse(Console.ReadLine());

            Small = a[0];
            for (int i = 0; i < a.Length - 1; i++)
            {
                if (a[i] < Small)
                {
                    Small = a[i];
                    Position = i;
                }
            }

            Console.WriteLine("\nThe Smallest Number is " + Small);
            Console.WriteLine("Its Position is " + (Position + 1));

            Console.ReadLine();
        }

    }

Output : 


No comments:

Post a Comment