Developpement/23DEV1.1/TPS1/TP01/12-Tableau/Tableau-Multidimensionnel/Magic.c

64 lines
1.1 KiB
C

#include <stdio.h>
#include <stdlib.h>
int main(void) {
int numdif = 0, n, diff, in = 0, nos = 0;
int compte = 1, i, j, resval, li, co, di;
int rep;
int tab[3][3];
int tabv[10];
for (i = 0 ; i < 3 ; i++){
for (j = 0 ; j < 3 ; j++){
printf("Entrez une valeur pour la case %d : ", compte);
scanf("%d", &rep);
tab[i][j] = rep;
compte++;
}
}
for (i = 0 ; i < 3 ; i++){
for (j = 0 ; j < 3 ; j++){
printf("%3d", tab[i][j]);
}
printf("\n");
}
for (i = 0 ; i < 10; i++){
for(j = 0 ; j < 10 ; j++){
n = tab[i][j];
if (n>=1 || n<=9){
resval = 1;
}else{
resval = 0;
}
for(int k = 0 ; k < 10 ; k++){
if (tabv[k] != n){
diff = -1;
}else{
diff = 0;
}
}
if (diff == -1){
tabv[in] = n;
nos++;
in++;
}
}
}
if(tab[0][0]+tab[0][1]+tab[0][2] = tab[1][0]+tab[1][1]+tab[1][2] = tab[2][0]+tab[2][1]+tab[2][2])
{
li = 1;
}else{
li = 0;
}
if(tab[0][0]+tab[1][0]+tab[2][0] = tab[0][1]+tab[1][1]+tab[2][1] = tab[0][2]+tab[1][2]+tab[2][2])
{
co = 1;
}else{
co = 0;
}
if(tab[0][0]+tab[1][1]+tab[2][2] = tab[2][0]+tab[1][1]+tab[0][2]){
di = 1;
}else{
di = 0;
}
}