Advertisement
Guest User

After Lunch Fun 2

a guest
Feb 19th, 2020
395
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.03 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp1
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             Console.WriteLine("ANSWER --- Output Value: {0}", lowPosNotIn(new int[] { 1, 3, 6, 4, 1, 2 }));
  10.             Console.WriteLine("ANSWER --- Output Value: {0}", lowPosNotIn(new int[] { 1, 2, 3 }));
  11.             Console.WriteLine("ANSWER --- Output Value: {0}", lowPosNotIn(new int[] { -1, -3 }));
  12.             Console.WriteLine("ANSWER --- Output Value: {0}", lowPosNotIn(new int[] { 1, -8, 3, 888, 6, -4, 1, 2, 3, 4, 5, 7, 8, 9, 10, 1024, 65536, 1  }));
  13.             Console.ReadLine();
  14.         }
  15.         private static int lowPosNotIn(int[] arrIN)
  16.         {
  17.             Array.Sort(arrIN);
  18.             int lowPositive = 1;
  19.             foreach(int i in arrIN)
  20.             {
  21.                     if (((i > lowPositive || lowPositive > i) != true) && (i>0))
  22.                     {
  23.                         lowPositive++;
  24.                     }
  25.             }
  26.             return lowPositive;
  27.         }
  28.     }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement