A8 Write a program to find the minimum odd number in an array

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

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


            for (int i = 0; i < a.Length; i++)
            {
                if (a[i] % 2 == 1)
                {
                    if (MinOdd == 0)
                    {
                        MinOdd = a[i];
                    }
                    else if (MinOdd > a[i])
                    {
                        MinOdd = a[i];
                    }
                }
            }

            Console.WriteLine("\nMinimum Odd Number in an array is : " + MinOdd);
            Console.ReadLine();
        }

    }

Output : 


No comments:

Post a Comment