Advertisement
Guest User

mosca2.c

a guest
Jan 29th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.87 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. int mon(int my, int mx, int mloc[][5], int c) {
  5.     int x, y, sn, se, ss, so;
  6.  
  7.     if ((my>=0) && (mx<5) && (my<5) && (mx>=0) && (mloc[my][mx] == 0)) { // ¿ES VÁLIDA LA POSICIÓN EN LA QUE ESTOY AHORA?
  8.         mloc[my][mx] = c; // PISAR LA MONEDA
  9.  
  10.         if (c==25) {
  11.             printf("\nSOLUCION:\n");
  12.             for(y=0;y<5;y++) {
  13.                 for(x=0;x<5;x++) {
  14.                     printf(" %2d", mloc[y][x]);
  15.                 }
  16.                 printf("\n");
  17.             }
  18.            
  19.             return 1;
  20.         }
  21.        
  22.         sn = mon(my - 1, mx, mloc, c+1);
  23.         se = mon(my, mx + 1, mloc, c+1);
  24.         ss = mon(my + 1, mx, mloc, c+1);
  25.         so = mon(my, mx - 1, mloc, c+1);
  26.        
  27.         mloc[my][mx] = 0; // "DESPISAR" la moneda
  28.     }
  29.    
  30.     return sn + se + ss + so;
  31. }
  32.  
  33. int main() {
  34.     int mloc[5][5]={{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0},{0,0,0,0,0}};
  35.     int my=2, mx=2, c=1;
  36.    
  37.     mon(my,mx,mloc,c);
  38.    
  39.    
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement