Program for finding missing number in between array of integer.Ex: int[] arrayValue={1,4,8,13};Answer: 2,3,5,6,7,9,10,11,12
HiRefer following example.
int[] array = { 1, 3, 6, 8, 14, 18 }; stringbuilder sbr = new stringbuilder(); for (int i = 0; i < array.length - 1; i++) { for (int j = array[i]; j < array[i + 1]; j++) { var temp = j + 1; if (temp < array[i + 1]) { sbr.append(temp); } } } console.writeline(sbr.tostring()); console.read();
int[] array = { 1, 3, 6, 8, 14, 18 };
stringbuilder sbr = new stringbuilder();
for (int i = 0; i < array.length - 1; i++)
{
for (int j = array[i]; j < array[i + 1]; j++)
var temp = j + 1;
if (temp < array[i + 1])
sbr.append(temp);
}
console.writeline(sbr.tostring());
console.read();
int[] A = { 1, 5, 8, 10, 11, 16 };for (int i = 0; i < A.Length-1; i++) { int num = A[i + 1] - A[i]; for (int j = 1; j < num; j++) { Console.Write(A[i] + j+” “); } } Console.ReadLine();
int[] array = { 1, 3, 6, 8, 14, 18 }; StringBuilder sbr = new StringBuilder();
for (int i = 0; i <array.Length-1; i++) { if (array[i] < array[i + 1]) { int startval = array[i]; int endval = array[i + 1]; for (int j = startval+1; j < endval; j++) { sbr.Append( j+ " "); } } } Console.WriteLine(sbr.ToString()); Console.ReadKey();
for (int i = 0; i <array.Length-1; i++)
if (array[i] < array[i + 1])
int startval = array[i];
int endval = array[i + 1];
for (int j = startval+1; j < endval; j++)
sbr.Append( j+ " ");
Console.WriteLine(sbr.ToString());
Console.ReadKey();