Código:
#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;
}




