C/Visual C - duda con punteros[cuadrado magico]

 
Vista:
sin imagen de perfil

duda con punteros[cuadrado magico]

Publicado por rodrigo (1 intervención) el 05/07/2014 21:53:13
bueno lo que sucede es que tengo que hacer un trabajo para la U.. y se trata de crear un cuadrado magico... que es que todas las sumas de los cuadrados de el mismo resultado.... el problema que tengo es que no se como hacer una matriz bidimensional variable.. lo he intentado muchas cosas. pero veo que aun me falta.. pero tengo q entregar este trabajo.. y no se como hacerlo.. a y se me olvida.. es que todo el programa tiene que se por obliación con funciones.. y tengo algo.. pero por motivos que no se.. no me funciona el programa. me compila.. pero solo qeda ai.. si algien tuviera algo de tiempo plz.. :/


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
 
void inicializar_arreglo (int **a, const int j){
    int x,y;
    for(x=0; x<j; x++){
        for(y=0; y<j; y++){
            (a[y][x]=0);
        }
    }
}
 
void materializar_arreglo(int **a, const int j){
    int w, y, x, z, tx, ty;
    (w=j*j);
    (y=0);
    (x=j/2);
    (tx=0);
    (ty=0);
    for(z=1; z<=w; z++){
        (a[y][x]=z);
        (ty=y);
        (tx=x);
        (y--);
        if(y<0){
            (y=j-1);
        }
        (x--);
        if(x<0){
            (x=j-1);
        }
        if(a[y][x]>0){
            (y=ty+1);
            (x=tx);
        }
    }
}
 
int main(){
    int i , j , k , w , x , y , z , tx , ty ;
    printf("||CUADRADO MAGICO||\n\n");
    printf("Ingrese un numero del cuadrado magico.\n\n");
    scanf("%d",&i);
    while(i<=2 | i%2==0){
        printf("Ingrese un numero impar mayor o igual que 3.\n\n");
        scanf("%d",&i);
        printf("\n");
    }
    int arr[i][i];
    inicializar_arreglo(arr,i);
    materializar_arreglo(arr,i);
 
 
    for(j=0; j<i; j++){
                for(k=0; k<i; k++){
                        printf("[%3d] ",arr[j][k]);
                        }
                printf("\n\n");
                }
    return 0;
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de JuanC

duda con punteros[cuadrado magico]

Publicado por JuanC (35 intervenciones) el 06/07/2014 14:29:30
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int i , j , k , w , x , y , z , tx , ty ;
    int **arr;
    printf("||CUADRADO MAGICO||\n\n");
    printf("Ingrese un numero del cuadrado magico.\n\n");
    scanf("%d",&i);
    while(i<=2 | i%2==0){
        printf("Ingrese un numero impar mayor o igual que 3.\n\n");
        scanf("%d",&i);
        printf("\n");
    }
    arr = new int*[i];
    for(int n=0; n<i; n++)
        arr[n] = new int[i];
 
    inicializar_arreglo(arr,i);
    materializar_arreglo(arr,i);

Saludos, desde Baires, JuanC
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar