Exclusive Clothing Sale On Soft & Soothe

Get up to 63% off on our latest collection.

Shop Now

Find all missing numbers from a given array in C#

 

Find all missing numbers from a given array in C#


C# Code

        static void FindMissingNumbers()

        {

            int[] array = { 1, 2,4, 5, 6,9,10 };

            int length = array.Length;

 

            int diff = array[0] - 0;

 

            for (int i = 0; i < length; i++)

            {

                // Check if diff and arr[i]-i

                // both are equal or not

                if (array[i] - i != diff)

                {

                    // Loop for consecutive

                    // missing elements

                    while (diff < array[i] - i)

                    {

                        Console.WriteLine(i + diff + " ");

                        diff++;

                    }

                }

            }

        }


output




Share this

Related Posts

Previous
Next Post »

Exclusive Clothing Sale On Soft & Soothe

Get up to 63% off on our latest collection.

Shop Now