Difficulty implementing chessboard [closed]

1

I need to implement the code that manages a chessboard in ppm. It would be in the standard 8x8 format, with the user's option to set the pixels quantity, the doubt would be at the time of looping to "multiply" the pixels. In the code below it is coming out in the 8x8 standard:

#include <stdio.h>

int main()
{
    int larg, alt;
    larg = alt = 8;

    printf("P2\n");
    printf("%d\t%d\n", larg, alt);
    printf("255\n");

    int i, j;
    int tamanho = 2;

    for(i = 0; i < larg; i++){
        for( j = 0; j < alt; j++){
            if((i + j) %2 != 0){
                    printf("0\t");
            }
            else{
                    printf("255\t");
            }
        }
        printf("\n");
    }
    return 0;
}

I hope it has become clear, and I apologize for any possible error, as this is my first question.

    
asked by anonymous 01.10.2018 / 04:48

1 answer

0

First I think you are drawing the board starting with the columns, not the lines. But considering that the board is square, that would not make any difference ...

for(i = 0; i < larg; i++){
    for(k = 0; k < tamanho; k++){
        for( j = 0; j < alt; j++){
            for(l = 0; l < tamanho; l++){
                if((i + j) %2 != 0){
                        printf("0\t");
                }
                else{
                        printf("255\t");
                }
            }
        }
        printf("\n");
    }
}

I believe this should work.

    
01.10.2018 / 16:35