Q:

Write a C# program which will accept a list of integers and checks how many integers are needed to complete the range

0

Write a C# program which will accept a list of integers and checks how many integers are needed to complete the range

Sample Output:

4
9

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
public class Example
{
       public static int consecutive_array(int[] input_Array)
        {
         Array.Sort(input_Array);
         int ctr = 0;
         for(int i = 0; i < input_Array.Length - 1; i++){
           ctr += input_Array[i+1] - input_Array[i] - 1;
          }
        return ctr;
         }
        
    public static void Main()
        {
             Console.WriteLine(consecutive_array(new int[] {1,3, 5,6,9}));
             Console.WriteLine(consecutive_array(new int[] {0,10}));
        }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now