// Arup Guha
// 8/31/2023
// Code for COP 3502 Quiz 1 Version B Question 3

#include <string.h>
#include <stdio.h>
#include <stdlib.h>

char** checkerboard(int n);

int main() {

    // Call function, print board.
    char** board = checkerboard(10);
    for (int i=0; i<10; i++)
        printf("%s\n", board[i]);

    // Clean up.
    for (int i=0; i<10; i++)
        free(board[i]);
    free(board);

    return 0;
}

char** checkerboard(int n) {

    // Allocate n pointers.
    char** res = calloc(n, sizeof(char*));

    // Do each row.
    for (int i=0; i<n; i++) {

        // Allocate this row.
        res[i] = calloc(n+1, sizeof(char));

        // Key is to use mod...this way we shorten the code.
        for (int j=0; j<n; j++) {
            if ( (i+j)%2 == 0)
                res[i][j] = 'X';
            else
                res[i][j] = 'O';
        }

        // Not necessary but this was requested in the question.
        res[i][n] = '\0';
    }

    // Ta da!
    return res;
}
