#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>

void display(int a, int b,int tableau[][b]){
    for(int p = 0; p<=37; p++){
            printf("_");
        }
        printf("\n");
    for(int i = 1; i<=9; i++){
        for(int j = 1; j<=9; j++){
            printf(" | ");
            if (tableau[i-1][j-1] == 0)
                printf(" ");
            else
                printf("%d",tableau[i-1][j-1]);
        }
        printf(" |");
        printf("\n");
        for(int p = 0; p<=37; p++){
            printf("_");
        }
        printf("\n");
    }
}


bool is_not_in_line(int x, int i, int a, int b, int tableau[][b]){
    for(int j = 1; j<=9; j++){
        if(tableau[i][j-1] == x){
            return false;
        }
    }
    return true;
}

bool is_not_in_colon(int x, int j, int a, int b, int tableau[][b]){
    for(int i = 1; i<=9; i++){
        if(tableau[i-1][j] == x){
            return false;
        }
    }
    return true;
}

void is_not_in_square(int x, int xi, int xj, int a, int b, int tableau[][b]){
    int square_i;
    int square_j;
    if (xi%3 == 2)
        square_i = xi-1;
    else if (xi%3 == 3)
        square_i = xi-2;
    else square_i = xi;

    if (xj%3 == 2)
        square_j = xj-1;
    else if (xj%3 == 3)
        square_j = xj-2;
    else square_j = xj;

    printf("position du carré : i = %d , j = %d", square_i, square_j);
}






int main() {

    int sudoku[9][9] = {
    {5, 3, 0, 0, 7, 0, 0, 0, 0},
    {6, 0, 0, 1, 9, 5, 0, 0, 0},
    {0, 9, 8, 0, 0, 0, 0, 6, 0},

    {8, 0, 0, 0, 6, 0, 0, 0, 3},
    {4, 0, 0, 8, 0, 3, 0, 0, 1},
    {7, 0, 0, 0, 2, 0, 0, 0, 6},

    {0, 6, 0, 0, 0, 0, 2, 8, 0},
    {0, 0, 0, 4, 1, 9, 0, 0, 5},
    {0, 0, 0, 0, 8, 0, 0, 7, 9}
                        };

    display(9, 9, sudoku);
    printf("\n");
    printf("Le chiffre n'est pas dans la ligne :\n%s\n", is_not_in_line(7, 0, 9, 9, sudoku) ? "true" : "false");
    printf("Le chiffre n'est pas dans la colonne :\n%s\n", is_not_in_colon(4, 0, 9, 9, sudoku) ? "true" : "false");
    is_not_in_square(4, 5, 7, 9, 9, sudoku);
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: