C code

Given numRows and numColumns, print a list of all seats in a theater. Rows are numbered, columns lettered, as in 1A or 3E. Print a space after each seat, including after the last. Ex: numRows = 2 and numColumns = 3 prints:

1A 1B 1C 2A 2B 2C
#include

int main(void) {
int numRows;
int numColumns;
int currentRow;
int currentColumn;
char currentColumnLetter;

scanf("%d", &numRows);
scanf("%d", &numColumns);

/* Your solution goes here */

printf("\n");

return 0;
}

Respuesta :

tonb

Answer:

for(currentRow=1; currentRow<=numRows; currentRow++) {

 for(currentColumn=0; currentColumn<numColumns; currentColumn++) {

   printf("%d%c ", currentRow, 'A'+currentColumn);

 }

}

Explanation:

By treating the column as a character, you can create the correct letter by adding 'A' to the column number (starting at 0). That way, you don't need the currentColumnLetter.

Of course this breaks if you have more columns than there are alphabet letters.