95.8k views
7 votes
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("\\");

return 0;
}

User Kalee
by
3.4k points

1 Answer

8 votes

Answer:

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

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

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

}

}

Step-by-step 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.

User ChrisW
by
3.9k points