Solution
Check each and every number index. The number is available in the array it will return that number index or it will return -1. After we get index, check the condition is equal to -1 or not. If index equal to -1, that number will print in the Console. Then, check, that number equal to 100. If This not equal to 100, the Increment operator increases value and go to the loop line.
- using System;
-
- namespace PlayingwithCSharp
- {
- public class Print1To100MissingNumberInArrayWithoutLoop
- {
- public static void MissingNumber()
- {
- int[] givenArray = new int[99];
- int incrementValue = 1, arrayPosion = 0 , one = 1 ;
- #region Assign Value to Array
-
- givenArray[0] = 1;
- givenArray[1] = 46;
- givenArray[2] = 34;
- givenArray[3] = 23;
- givenArray[4] = 26;
- #endregion
- Array.Sort(givenArray);
-
- Loop:
- var isPosition = Array.IndexOf(givenArray, incrementValue);
- if(isPosition == -1)
- {
- System.Console.Write(incrementValue + " ");
- if (incrementValue != 100)
- {
- arrayPosion++;
- incrementValue++;
- goto Loop;
- }
- else
- {
- System.Console.WriteLine("\nMissing Value 1 to 100 Printed Above");
- }
- }
- else
- {
- if (incrementValue == 100)
- {
- System.Console.WriteLine("\nMissing Value 1 to 100 Printed Above");
- }
- else
- {
- incrementValue++;
- goto Loop;
- }
- }
- Console.ReadLine();
- }
- }
- }
-
-
-
-
-
-
-
-