Salut,
je t'envoi un programme que j'ai fait, et ça marche: c'est AZIZ Rachid
#include<stdio.h>
#define N 50
#define M 40
#include<conio.h>
#include<math.h>
float tampon[N][M+N],d[N];
int n,indice[N],m;
int chercol(void);
int cherlig(int c );
void simp(int l, int c);
void affiche(void);
void saisie(void);
void scalaire(void);
/*****************FONCTION PRINCIPALE*************************/
int main(void)
{ int l,c;
saisie();
for(;;)
{
affiche();
c=chercol();
if(c==-1)
break;
// printf("les tableaux sont:");
printf("\n%f",tampon[n][c]);
l=cherlig(c);
if(l==-1)
break;
indice[l]=c;
simp(l,c);
scalaire();
}
getch();
}
//*********************RECHERCHE DE LA COLONNE DU PIVOT**********************
int chercol(void)
{ int i,memo;
float min;
min =tampon[n][0];
memo=0;
for(i=1;i<m+n;i++)
if(min>tampon[n][i])
{min =tampon[n][i];
memo=i; }
if(min>=0)
return(-1);
else
return(memo);
}
//*******************RECHERCHE DE LA LIGNE DU PIVOT**************************
int cherlig(int c)
{ int i,memo;
float min;
i=0;
while(tampon[i][c]<=0)
{i++;
if(i==n-1)
return(-1);}
min= tampon[i][m+n]/tampon[i][c];
memo=i;
for(i=0;i<n;i++)
if((tampon[i][c]!=0) && ( min > tampon[i][m+n]/tampon[i][c]) &&(tampon[i][c]>0))
{min = tampon[i][m+n]/tampon[i][c];
memo=i;}
return(memo);
}
//*******************************SIMPLEXE************************************
void simp(int l,int c)
{ int i,j;
float pivot;
pivot=tampon[l][c];
for(j=0;j<m+n+1;j++)
tampon[l][j] = tampon[l][j]/pivot;
for(i=0;i<n;i++)
if(i!=l)
{ pivot=tampon[i][c];
for(j=0;j<m+n+1;j++)
tampon[i][j]= tampon[i][j] - pivot * tampon[l][j];}
}
//*************************LES DELTAS(I,J)***********************************
void scalaire(void)
{ int i,j;
float L;
for(j=0;j<m+n+1;j++)
{ L=0;
for(i=0;i<n;i++)
L= L + d[indice[i]]*tampon[i][j];
if(j == m+n)
tampon[n][j]=L;
else
tampon[n][j]=d[j]-L;}
}
//******************************AFFICHAGE**************************************
void affiche(void)
{ int l,c,i;
gotoxy(8,5);
cprintf("LES TABLEAUX :");
for(l=0;l<n+1;l++)
{ i=1;
for(c=0;c<m+n+1;c++)
{gotoxy(3*n*(i++),l+10);
printf("%.1f",tampon[l][c]);}
}
getch();
}
//*****************************LA SAISIE*************************************
void saisie(void)
{ int p,l,c;
window(1,1,80,25);
textbackground(1);
clrscr();
window(4,5,75,24);
textbackground(9);
clrscr();
textcolor(WHITE);
gotoxy(4,2);
cprintf("CE PROGRAMME PEUT RESOUDRE LE PROBLEME");
gotoxy(4,3);
cprintf("LINEAIRE DE LA FORME A*X<=b");
gotoxy(4,4);
cprintf("PAR LA METHODE Du SIMPLEX");
gotoxy(4,5);
gotoxy(4,10);
cprintf("Le problème à la forme suivante:");
gotoxy(4,12);
cprintf("a11*x1+.....+a1m*xm<=b1");
gotoxy(4,13);
cprintf(". ..... . <=.");
gotoxy(4,14);
cprintf("an1*x1+.....+anm*xm<=bn");
gotoxy(4,15);
cprintf("MIN( c1*x1+.......+cn*xm).");
gotoxy(4,17);
cprintf(" Pour résoudre le probléme d'affectation des engins aux chantiers à cout minimal " );
gotoxy(4,18);
cprintf("les dimensions du problème:");
gotoxy(4,19);
cprintf("Donnez le nombre des lignes n= ");
scanf("%d",&n);
gotoxy(4,20);
cprintf("Donnez le nombre des colonnes m= ");
scanf("%d",&m);
p=n;
for(l=0;l<n;l++)
indice[l]=p++;
window(1,1,80,25);
textbackground(1);
clrscr();
window(1,1,80,40);
textbackground(9);
clrscr();
textcolor(WHITE);
gotoxy(10,6);
cprintf(" Donnez la matrice A");
for(l=0;l<n;l++)
for(c=0;c<m;c++)
{ gotoxy(14*c+12,l+9);
cprintf("A[%d][%d]=",l,c);
scanf("%f",&tampon[l][c]);}
cprintf("\n Donnnez le vecteur b\n");
for(l=0;l<n;l++)
{
gotoxy(39,13+l);
cprintf("b[%d]=",l);
scanf("%f",&tampon[l][m+n]);}
cprintf("\n donnez le vecteur c\n");
for(c=0;c<n;c++)
{
gotoxy(49,18+c);
cprintf("c[%d]=",c);
scanf("%f",&d[c]);}
for(c=0;c<m+n;c++)
{ if( c < n )
tampon[n][c]=d[c];
else
{tampon[n][c]=0;
d[c]=0;}}
for(c=n;c<m+n;c++)
for(l=0;l<n;l++)
if( (l+n) == c )
tampon[l][c]=1;
else
tampon[l][c]=0;
tampon[n][m+n]=0;
}