Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- int mon(int my, int mx, int mloc[][5], int c) {
- int x, y, sn, se, ss, so;
- if ((my>=0) && (mx<5) && (my<5) && (mx>=0) && (mloc[my][mx] == 0)) { // ¿ES VÁLIDA LA POSICIÓN EN LA QUE ESTOY AHORA?
- mloc[my][mx] = c; // PISAR LA MONEDA
- if (c==25) {
- printf("\nSOLUCION:\n");
- for(y=0;y<5;y++) {
- for(x=0;x<5;x++) {
- printf(" %2d", mloc[y][x]);
- }
- printf("\n");
- }
- return 1;
- }
- sn = mon(my - 1, mx, mloc, c+1);
- se = mon(my, mx + 1, mloc, c+1);
- ss = mon(my + 1, mx, mloc, c+1);
- so = mon(my, mx - 1, mloc, c+1);
- mloc[my][mx] = 0; // "DESPISAR" la moneda
- }
- return sn + se + ss + so;
- }
- int main() {
- 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}};
- int my=2, mx=2, c=1;
- mon(my,mx,mloc,c);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement