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 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
| #include<stdio.h>
#include<stdlib.h>
#include<conio.h>
// les prototypes
void afficheMatrice(float **mat , int max );
void afficherVect(float *b , int max);
void remplirMatrice(float **mat, int max);
void remplirVect(float *b , int max);
void prod(float **mat,float *b,int max);
//début main :(
int main()
{
float **mat , *b, *t;
int i,n;
printf("Bonjour, Entrez la taille de la matrice \n");
scanf("%d",&n);
// Allocation mémoire
t = (float*)malloc(n*sizeof(float));
b = (float*)malloc(n*sizeof(float));
mat = (float**)malloc(n*sizeof(float*));
for(i=0 ; i<n ;i++)
{
mat[i] = (float*)malloc(n*sizeof(float));
}
printf("Le produit de A et x !!\n");
remplirMatrice(mat,n);
remplirVect(b,n);
prod(mat,b,n);
getch();
return 0;
}
//fin main :D
void afficheMatrice(float** mat, int n)
{
int i,j;
printf("\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++ )
{
printf("%1.f \t",mat[i][j]);
}
printf("\n");
}
}
void afficherVect(float *b,int n)
{
int i;
printf("\n");
for(i=0;i<n;i++ )
printf(" %f ",b[i]);
printf("\n");
}
void remplirMatrice(float **mat , int n)
{
int i,j;
for(i=0;i<n;i++)
for(j=0;j<n;j++ )
{
mat[i][j] = 0 ;
}
for(i = 0 ; i<n ; i++ )
for(j = 0 ; j<n ; j++ )
{
system("cls");
afficheMatrice(mat,n);
printf("Remplir la case(%d,%d) \n",i,j);
scanf("%f",&mat[i][j]);
system("cls");
}
}
void remplirVect(float *b , int n)
{
int i;
for(i=0;i<n;i++)
b[i] = 0 ;
for(i=0;i<n;i++)
{
system("cls");
afficherVect(b,n);
printf("Remplir la case(%d) \n",i);
scanf("%f",&b[i]);
system("cls");
}
}
void prod(float **mat,float *b,int n)
{
int h,k;float *t;
for(k=0;k<n;k++)
{
t[k]=0;
for(h=0;h<n;h++)
{
t[k]+=mat[k][h]*b[h];
}
}
for(k=0;k<n;k++)
{
for(h=0;h<n;h++)
{
printf("t[%d]==%f \t",k+1,&t[k+1]);
}
}
} |
Partager