bonsoir ,
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
118
119
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
double **allocTab(int nbr)
{
    //allocation dynamique avec malloc.
    int i;
    double **tab;
    tab = malloc(nbr * sizeof(double*));
    if(tab == NULL)
        exit(EXIT_FAILURE);
    for(i = 0; i < nbr; i++)
    {
        tab[i] = malloc(nbr * sizeof(double));
        if(tab[i] == NULL)
            exit(EXIT_FAILURE);
    }
    return tab;
}
void initab(double **tab, int nbr)
{
    //initialitation avec la fonction rand();
    int i,j;
    srand(time(NULL));
    for(i=0; i<nbr; i++)
    {
        for(j=0; j<nbr; j++)
            tab[i][j]=rand()%5;
    }
 
}
void afficheTAB(double **tab,int nbr)
{
    //affichage de tableau.
    int i,j;
    for(i=0; i<nbr; i++)
    {
        printf("\n");
        for(j=0; j<nbr; j++)
            printf(" %.2f ",tab[i][j]);
    }
 
}
double **change(double **tab,int nbr)
{
    int i,j,k;
    for(k=0; k<nbr-1; k++)
    {
        for(i=k+1; i<nbr; i++)
        {
            if(i!=k&&tab[i][k]!=0)
            {
                for(j=0; j<nbr; j++)
                    tab[k][j]=tab[k][j]+tab[i][j];
                    //changement des lignes.
            }
        }
    }
    return tab;
}
double calculdet(double **tab,int nbr)
{
    int i;
    double det=1;
    for(i=0; i<nbr; i++)
    {
        det*=tab[i][i];
    }
    return det;
}
double**triangleMatrice(int nbr)
{
    double **tab;
    int i,j,k;
    double r;
    for(k=0; k<(nbr-1); k++)
    {
        for(i=k+1; i<nbr; i++)
        {
            if(tab[k][k]!=0)//si le pivot diffirent de 0
            {
                r=-(tab[i][k]/tab[k][k]);
                for(j=k; j<nbr; j++)
                    tab[i][j]=(tab[i][j]+(r*tab[k][j]));
            }
            else //sinon (pivot =0) on change les lignes puis on transforme la matrice
//en triangulaire
                tab=change(tab,nbr);
            tab=triangleMatrice(nbr);
        }
        printf(" le determinant est :%.2f",calculdet(tab,nbr));//on affiche le determinant
    }
    return tab;//retourner le tableau apres les changements
   /*je veux afficher le tableau apres la modification c'est pour ça il est renvoyer !*/
}
 
void Liberation(double **tab,int nbr)
{
    //liberer le tableau apres l'utilisation de malloc
    int i;
    for (i=0 ; i<nbr ; i++)
        free(tab[i]);
    free(tab);
}
 
int main()
{
    double**tab;
    int nbr;
    puts("entrer la dimension de tableau :");
    scanf("%d",&nbr);
    tab=allocTab(nbr);
    initab(tab,nbr);
    afficheTAB(tab,nbr);
    tab=triangleMatrice(nbr);
    afficheTAB(tab,nbr);
    Liberation(tab,nbr);
    return 0;
}
Ce code sert a calculer le determinant par methode de pivot de gauss.
le probleme se situe dans la fonction change et trianglematrice.
je veux savoir comment les reparer.
merci pour votre aide !