Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- float pow(float n,int p)
- {
- if (p==0)
- {
- return 1;
- }else
- {
- return pow(n,p-1)*n;
- }
- }
- float mineur(float m[3][3],int cl,int cc)
- {
- float num1,num2;
- int posnum=0;
- for (int l =0;l<3;l++)
- {
- for (int c =0;c<3;c++)
- {
- if(l==cl)
- { // printf("Break\n");
- break;
- }else if(c==cc)
- { // printf("continued\n");
- continue;
- }else
- {
- posnum++;
- switch (posnum)
- {
- case 1:
- num1=m[l][c];
- break;
- case 2:
- num2=m[l][c];
- break;
- case 3:
- num2*=m[l][c];
- break;
- case 4:
- num1*=m[l][c];
- break;
- }
- }
- }
- }
- return num1-num2;
- }
- float cofacteur(float m[3][3],int l,int c)
- {
- return pow(-1,l+c+2)*mineur(m,l,c);
- }
- void aff(float m[3][3])
- {
- for(int l =0; l<3;l++)
- {
- for(int c = 0; c<3;c++)
- {
- printf("%.0f\t",m[l][c]);
- }
- printf("\n");
- }
- }
- int main()
- {
- /// input matrice
- float m[3][3],M[3][3];
- for(int l=0; l<3;l++)
- {
- for(int c = 0; c<3;c++)
- {
- scanf("%f",&m[l][c]);
- }
- }
- system("CLS"); /// to clear the input screen for a cleaner output
- printf("Martice:\n");
- aff(m);
- /// calcul du determinant
- float det=m[0][0]*(m[1][1]*m[2][2]-m[1][2]*m[2][1])-
- m[1][0]*(m[0][1]*m[2][2]-m[0][2]*m[2][1])+
- m[2][0]*(m[0][1]*m[1][2]-m[0][2]*m[1][1]);
- printf("Det(M)= %.2f\n",det);
- /// creation d'une matrice des cofacteurs aka comatrice
- for(int l=0; l<3;l++)
- {
- for(int c = 0; c<3;c++)
- {
- M[l][c]=cofacteur(m,l,c);
- }
- }
- printf("\n\nMatrice Cofacteur {Com(m)}:\n");
- aff(M);
- ////printf("\n\n");
- /// symétrie du matrice
- float x;
- for(int l=0; l<3;l++)
- {
- for(int c = 0; c<2;c++)
- {
- if(l<c)
- {
- continue;
- }
- x=M[l][c];
- M[l][c]=M[c][l];
- M[c][l]=x;
- }
- printf("\n");
- } /*
- printf("\n\nInverse du Matrice Cofacteur {t(Com(m))}:\n");
- aff(M); */
- printf("l'inverse du matrice tapee est m^-1=1/%.1f *\n",det);
- aff(M);
- //printf("\n\n%.0f\t%.0f\t%.0f\t%.0f\t",m[2][1],mineur(m,2,1),pow(-1,2+1+2),cofacteur(m,2,1));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement