Find Next Natural Number in Int Array
Back to: Logical Programming with CSharp
Find the next natural number in an integer array: A common coding challenge for algorithmic problem-solving.
Find the Natural number in int array.
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApp4 { internal class Program { static void Main(string[] args) { int[] ints = { 4,1, 2, 6, 8, 79 }; int nextNumber = 1; while (nextNumber>0 && nextNumber<=ints.Length) { var result=ints.Where(s=>s.Equals(nextNumber)).FirstOrDefault(); if(result==0) { Console.WriteLine(nextNumber); break; } else { nextNumber++; } } Console.ReadLine(); } } }