Complete the code for the following findSeats function that returns an int resul
ID: 3626533 • Letter: C
Question
Complete the code for the following findSeats function that returns an int result.Its purpose is to check whether its frist argument, a 2-dimensional integer array of numbers
representing seats taken at a theater, contains enough consecutive empty seats(the second arg)
on a desired row(the third argument). If the desired number of consecutive empty seats are available, it returns
the position in the row of the first available seat in the group. If there are not enough empty seats available,
it returns -1. Assume an empty seat is represented by 0 and an occupied seat is represented by
1 in the seats array.
The algorithm for the program is to find an empty seat in the desired row, then see if it is the
first of n consecutive empty seats. Assume global integer constants ROWS and COLS exist
that are the dimensions of the seats array
int findSeats (int seats[][_______], int empty, int row)
{
for ( int outer=0; outer < ________; outer++)
{
if ( seats[______][______] ==______)
{
int consecutive = 0;
for ( int inner =______; inner <______; inner++)
{
if (seats [row][inner] == 0)
______++;
else
break;
}
if ( consecutive >= ______)
return ______;
}
}
return -1;
}
Explanation / Answer
int findSeats (int seats[][a], int empty, int row)
{
for ( int outer=0; outer < a; outer++)
{
if ( seats[row][outer] ==0)
{
int consecutive = 0;
for ( int inner =0; inner <a; inner++)
{
if (seats [row][inner] == 0)
consecutive++;
else
break;
}
if ( consecutive >=a)
return 1;
}
}
return -1;
}