Advertisement
LucaVinci110898

Sudoku/es9_main.c

Feb 14th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.23 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include "es9.h"
  4.  
  5. /* Campo corretto */
  6. int campo1[DIM][DIM] = {
  7.     { 8, 2, 1, 5, 4, 6, 3, 7, 9 },
  8.     { 9, 6, 4, 8, 3, 7, 5, 2, 1 },
  9.     { 5, 3, 7, 2, 1, 9, 6, 8, 4 },
  10.     { 7, 1, 6, 4, 8, 2, 9, 5, 3 },
  11.     { 3, 4, 9, 7, 5, 1, 8, 6, 2 },
  12.     { 2, 8, 5, 6, 9, 3, 4, 1, 7 },
  13.     { 1, 5, 8, 9, 7, 4, 2, 3, 6 },
  14.     { 4, 7, 2, 3, 6, 5, 1, 9, 8 },
  15.     { 6, 9, 3, 1, 2, 8, 7, 4, 5 }
  16. };
  17.  
  18. /* Campo corretto */
  19. int campo2[DIM][DIM] = {
  20.     { 4, 8, 7, 9, 5, 2, 1, 3, 6 },
  21.     { 2, 9, 3, 6, 1, 4, 7, 5, 8 },
  22.     { 1, 6, 5, 7, 8, 3, 4, 9, 2 },
  23.     { 8, 2, 1, 3, 7, 5, 6, 4, 9 },
  24.     { 5, 7, 6, 8, 4, 9, 3, 2, 1 },
  25.     { 3, 4, 9, 1, 2, 6, 5, 8, 7 },
  26.     { 9, 1, 8, 5, 3, 7, 2, 6, 4 },
  27.     { 6, 5, 4, 2, 9, 1, 8, 7, 3 },
  28.     { 7, 3, 2, 4, 6, 8, 9, 1, 5 }
  29. };
  30.  
  31. /* Campo errato */
  32. int campo3[DIM][DIM] = {
  33.     { 2, 7, 3, 4, 8, 1, 9, 6, 5 },
  34.     { 5, 1, 4, 9, 3, 6, 8, 2, 7 },
  35.     { 6, 9, 3, 2, 7, 5, 1, 4, 3 },
  36.     { 8, 3, 1, 6, 5, 7, 2, 9, 4 },
  37.     { 7, 6, 9, 1, 4, 3, 5, 8, 1 },
  38.     { 4, 5, 1, 8, 1, 6, 7, 3, 6 },
  39.     { 9, 4, 5, 7, 2, 3, 6, 1, 8 },
  40.     { 3, 3, 8, 1, 6, 8, 4, 5, 9 },
  41.     { 1, 8, 6, 6, 9, 4, 3, 7, 2 }
  42. };
  43.  
  44. /* Campo errato */
  45. int campo4[DIM][DIM] = {
  46.     { 2, 7, 3, 0, 8, 1, 9, 6, 5 },
  47.     { 5, 1, 4, 9, 3, 6, 8, 2, 7 },
  48.     { 6, 9, 3, 2, 7, 5, 1, 4, 3 },
  49.     { 8, 3, 1, 6, 5, 7, 2, 9, 4 },
  50.     { 7, 6, 9, 1, 4, 3, 5, 8, 1 },
  51.     { 4, 5, 1, 8, 1, 6, 7, 3, 6 },
  52.     { 9, 4, 5, 7, 2, 3, 6, 1, 8 },
  53.     { 3, 0, 8, 1, 6, 8, 4, 0, 9 },
  54.     { 1, 8, 6, 6, 9, 4, 3, 7, 2 }
  55. };
  56.  
  57. /*
  58.  * Compilare con il comando `gcc -std=gnu89 -Wall -pedantic -o es9 es9.c es9_main.c`.
  59.  */
  60. int main() {
  61.  
  62.     int c;
  63.     int r;
  64.     int i;
  65.     i = 0;
  66.  
  67.     /* Riquadro */
  68.     for(r = 0; r < DIM; r = r+3){
  69.         for(c = 0; c < DIM; c = c+3){
  70.             i++;
  71.             printf("Riquadro %d -> %d\n",i,verifica_riquadro(campo1,r,c));
  72.         }
  73.     }
  74.  
  75.     /* Righe */
  76.     for(r = 0; r<DIM; r++){
  77.         printf("Riga %d -> %d\n",r,verifica_riga(campo1,r));
  78.     }
  79.  
  80.     /* Colonne */
  81.     for(c = 0; c<DIM; c++){
  82.         printf("Colonna %d -> %d\n",c,verifica_colonna(campo1,c));
  83.     }
  84.    
  85.     /* Campo */
  86.     printf("Campo %d\n",verifica_campo(campo1));
  87.  
  88.     return EXIT_SUCCESS;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement