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 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
| #include <stdio.h>
#include <stdlib.h>
#define taille 50;
int **creation(int N,int** matrice)
{
int I,J,i ;
matrice =(int**)malloc( N * sizeof(int*));
if( matrice == NULL )
{
fprintf(stderr,"Allocation impossible");
exit(EXIT_FAILURE);
}
for( i = 0 ; i < N ; i++ )
{
matrice[i] =(int*)calloc (N, sizeof(int));
if( matrice[i] == NULL )
{
fprintf(stderr,"Allocation impossible");
exit(EXIT_FAILURE);
}
}
for (I=0; I<N; I++){
for (J=0; J<N; J++)
{printf("1=> extremite initiale / 0=> extremite finale\n entrer la valeur du noeud [%d][%d]:",I,J);
scanf("%d",&matrice[I][J]);}
}
return matrice;
}
void affichage(int N,int **matrice) {
int I,J;
printf("La Matrice donnée :\n");
for (I=0; I<N; I++)
{
for (J=0; J<N; J++)
printf("%7d", matrice[I][J]);
printf("\n");
}
}
main()
{
int choix,*tab,I,N,J,**matrix;
do
{
printf(" ==============================================\n");
printf(" *** Menu *** \n");
printf(" ==============================================\n \n");
printf(" 1-Creation de la matrice \n");
printf(" 2-Afficher la matrice \n");
printf(" 0-quitter \n \n");
printf(" ==============================================\n \n");
printf("choix : ");
scanf("%d",choix);
switch(choix)
{
case 1 :
{
printf("Entrer le nombre des noeuds: \n");
scanf("%d", &N );
if(N < 50)
matrix=creation(N,matrix);
else
printf("Vous avez depassé le nombre maximum des noeuds accordé");
}break;
case 2 :
affichage(N,matrix);
break;
}
}while(choix!=0);
system("pause");
return 0;
} |
Partager