Find Missing number in sequential array

Given an integer array with sequential number write a program to find the missing number from given array.

Solution:

using System;
using System.Linq;

namespace Array 
{
 class Program {

  static void Main()
  {
       var sum = 0;
       var arr = new int[] { 3, 5, 6, 4, 1};
       for (int i = 1; i <= arr.Length + 1; i++) 
       {
          sum += i;
       } 

       Console.WriteLine($ "Missing number from sequential array is {sum - arr.Sum()}");
      Console.ReadLine();
  }
 }
}

Leave a Reply

Your email address will not be published. Required fields are marked *