Periyasamy Vellingirisamy
Write a program for finding an missing number in between array of integer using c#

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

By Periyasamy Vellingirisamy in C# on Jun 01 2020
  • Periyasamy Vellingirisamy
    Jul, 2020 3

    Hi
    Refer following example.

    1. int[] array = { 1, 3, 6, 8, 14, 18 };
    2. stringbuilder sbr = new stringbuilder();
    3. for (int i = 0; i < array.length - 1; i++)
    4. {
    5. for (int j = array[i]; j < array[i + 1]; j++)
    6. {
    7. var temp = j + 1;
    8. if (temp < array[i + 1])
    9. {
    10. sbr.append(temp);
    11. }
    12. }
    13. }
    14. console.writeline(sbr.tostring());
    15. console.read();

    • 2
  • Vara Prasad
    Nov, 2021 8

    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();

    • 0
  • Balasaheb Patil
    Jan, 2021 1

    int[] array = { 1, 3, 6, 8, 14, 18 };
    StringBuilder sbr = new StringBuilder();

    1. for (int i = 0; i <array.Length-1; i++)
    2. {
    3. if (array[i] < array[i + 1])
    4. {
    5. int startval = array[i];
    6. int endval = array[i + 1];
    7. for (int j = startval+1; j < endval; j++)
    8. {
    9. sbr.Append( j+ " ");
    10. }
    11. }
    12. }
    13. Console.WriteLine(sbr.ToString());
    14. Console.ReadKey();

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS