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
|
#include <stdio.h>
#include <stdlib.h>
#define ADR(p, n, x, y) \
((p)+((x)*(n)+(y)))
int main (void)
{
int nbr;
/* Controle de la valeur entree */
{
int ret;
do
{
printf ("Entrer un nombre impair : ");
ret = scanf ("%d", &nbr);
}
while (ret != 1 && (nbr % 2) == 0);
}
{
int *p_carreMag = malloc (sizeof *p_carreMag * nbr * nbr);
/* Initialisation des valeurs du tableau à 0 */
if (p_carreMag != NULL)
{
int a, b;
for (a = 0; a < nbr; a++)
{
for (b = 0; b < nbr; b++)
{
*ADR (p_carreMag, nbr, a, b) = 0;
printf ("[a%d] [b%d] = %d | ", a, b, *ADR (p_carreMag, nbr, a, b));
}
printf ("\n");
}
free (p_carreMag),p_carreMag=NULL;
}
}
system ("PAUSE");
return 0;
} |
Partager