Résolution pivot de Gauss
bonjour est-ce que quelqu'un pourrait m'aider svp mon programme ne fonctionne pas le traitemen n'est pas bon mais je vois pas où :?
merci de votre aide.
Code:
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 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142
| #define N 50
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
main()
{
//déclaration des variables
int n,i,j,k;
float A[N][N],B[N],X[N],C;
printf("\n\t\t !!!!RESOLUTION D'UN SYSTEME CRAMER-GAUSS!!!!\n");
//nombre d'inconnu
do
{
printf("\n\nQuel est le nombre d'inconnu (0<N<50)? ");
scanf("%d",&n);
}
while((n<=0)||(n>N));
//acquisition de la matrice A
system("cls");
printf("\n\t\t !!!!RESOLUTION D'UN SYSTEME CRAMER-GAUSS!!!!\n");
printf("\n\n\tSaisie des coefficients de la matrice A\n");
printf("\nL'lment diagonal doit tre diffrent de 0\n\n");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
// do
//{
printf("Entrez le coefficient A %d %d: ",i+1,j+1);
scanf("%f",&A[i][j]);
// }
//while(A[i][i]==0);
}
}
printf("\n\nMatrice A:\n\n\t");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%5.2f ",A[i][j]);
}
printf("\n\t");
}
getche();
//acquisition du second membre
system("cls");
printf("\n\t\t !!!!RESOLUTION D'UN SYSTEME CRAMER-GAUSS!!!!\n");
printf("\n\n\tSaisie des coefficients du second membre B\n\n");
printf("\nLe nombre d'lments est: %d\n\n",n);
for(i=0;i<n;i++)
{
printf("Entrez le coefficient B %d: ",i+1);
scanf("%f",&B[i]);
}
printf("\n\nSecond membre B:\n\n\t");
for(i=0;i<n;i++)
{
printf("%5.2f\n\t",B[i]);
}
getche();
//affichage de votre système
system("cls");
printf("\n\t\t !!!!RESOLUTION D'UN SYSTEME CRAMER-GAUSS!!!!\n");
printf("\n\nMatrice A:\n\n\t");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%5.2f ",A[i][j]);
}
printf("\n\t");
}
printf("\n\nSecond membre B:\n\n\t");
for(i=0;i<n;i++)
{
printf("%5.2f\n\t",B[i]);
}
printf("\n\nInconnu X:\n\n\t");
for(i=0;i<n;i++)
{
printf(" X %d\n\t",i+1);
}
getche();
//algorithme de Gauss
system("cls");
printf("\n\t\t !!!!RESOLUTION D'UN SYSTEME CRAMER-GAUSS!!!!\n");
for(i=0;i<n;i++)
{
C=A[i][i];
for(j=0;j<n;j++)
{
A[i][j]=A[i][j]/C;
}
B[i]=B[i]/C;
for(k=i+1;k<n;k++)
{
for(j=0;j<n;j++)
{
A[k][j]=A[k][j]-A[k][i]*A[i][j];
}
B[k]=B[k]-A[k][i]*B[i];
}
}
printf("\nVoici votre sytme selon l'agorithme de Gauss");
printf("\n\nMatrice A:\n\n\t");
for(i=0;i<n;i++)
{
for(j=0;j<n;j++)
{
printf("%5.2f ",A[i][j]);
}
printf("\n\t");
}
printf("\n\nSecond membre B:\n\n\t");
for(i=0;i<n;i++)
{
printf("%5.2f\n\t",B[i]);
}
printf("\n\nInconnu X:\n\n\t");
for(i=0;i<n;i++)
{
printf(" X %d\n\t",i+1);
}
getche();
} |