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
| void creer_matrice(int nb,int mat[nb][nb]){
int i,j;
for(i = 0; i < nb+1; i++)
{
for(j = 0; j < nb+1; j++)
{
mat[i][j]=0;
}
}
mat[0][0]=2;
mat[0][1]=3;
mat[1][0]=6;
mat[1][1]=-5;
}
void afficher_matrice(int nb,int mat[nb][nb]){
int i,j;
for(i=0; i <=nb; i++){
for(j = 0; j <=nb; j++){
printf("%i",mat[i][j]);
}
printf("\n");
}
}
int main(){
int nb_ut;
do{
printf("Entrez la taille de la matrice (2,4,8 ou 16):");
scanf("%i",&nb_ut);
printf("\n");
}while(nb_ut!=1 && nb_ut!=2 && nb_ut!=4 && nb_ut!=8 && nb_ut!=16); /* verification de nb_ut*/
nb_ut--; /*pour dimmensionner la matrice, on part de zero*/
int mat[nb_ut][nb_ut]; /*déclaration de la matrice*/
creer_matrice(nb_ut,mat); /*creer la matrice de zero*/
afficher_matrice(nb_ut,mat); /*affichage de la matrice d'origine pour verif*/
} |
Partager