A7 Write a program to check weather given array is consecutive or not

    class Program
    {
        static void Main(string[] args)
        {
            int[] a = new int[5];
            bool flag = true;

            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 - 1; i++)
            {
                if (a[i] + 1 != a[i + 1])
                {
                    flag = false;
                    break;
                }
            }

            if (flag)
            {
                Console.WriteLine("\nGiven Array elemenets are Consecutive");
            }
            else
            {
                Console.WriteLine("\nGiven Array elemenets are Not Consecutive");
            }
            Console.ReadLine();
        }

    }

Output 1:

 Output 2:


No comments:

Post a Comment