public static int ClosestEmptySeat(bool[] seats, int wantedSeat)
if (seats[wantedSeat] == true)
while (i != seats.Length)
if (wantedSeat + i < seats.Length)
if (seats[wantedSeat + i] == true)
if (seats[wantedSeat - i] == true)
public static void Main()
bool[] seats = new bool[5];
for (int i = 0; i < 5; i++)
for (int j = 0; j < 5; j++)
Console.WriteLine("Enter your wanted seat");
wantedSeat = int.Parse(Console.ReadLine());
seat = ClosestEmptySeat(seats, wantedSeat);
Console.WriteLine("There are no empty seats left");
Console.WriteLine("Your seat will be: " + seat);