#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<math.h>
float pivo,cero;
int max=30;
int c,n,i,i1,j,k,m;
float epc,A[20][20];
void main()
{
clrscr();
gotoxy(20,1);
printf(" M E T O D O D E G A U S S J O R D A N ");
gotoxy(25,3);
cout<<"DAME EL TAMA•O DE MATRIZ:";
cin>>n;
gotoxy(15,5);
printf("DAME LOS COEFICIENTES: ");
if (n==3){
gotoxy(13,6);
printf(" X1: X2: X3: = ");
gotoxy(13,7);
printf(" X1: X2: X3: = ");
gotoxy(13,8);
printf(" X1: X2: X3: = ");
}
if(n==4){
gotoxy(13,6);
printf(" X1: X2: X3: X4 = ");
gotoxy(13,7);
printf(" X1: X2: X3: X4 = ");
gotoxy(13,8);
printf(" X1: X2: X3: X4 = ");
gotoxy(13,9);
printf(" X1: X2: X3: X4 = ");
}
if(n>1 & n<20)
{
m=n+1;
for(i=1;i<=n;i++)
{
c=14;
for(j=1;j<=m;j++)
{
c=c+7;
gotoxy(c,i1+6);
cin>>A[i][j];
}
i1++;
}
for(i=1;i<=n;i++)
{
pivo=A[i][i];
for(j=1;j<=m;j++)
A[i][j]=A[i][j]/pivo;
for(k=1;k<=n;k++)
{
if(k!=i)
{
cero=-A[k][i];
for(j=1;j<=m;j++)
A[k][j]=A[k][j]+cero*A[i][j];
}
}
}
if(n==3){
printf("\n\n\n");
printf(" |");
for (j=1;j<=m;j++)
printf("\t%7.2f ",A[1][j]);
printf("\n");
printf(" |");
for (j=1;j<=m;j++)
printf("\t%7.2f ",A[2][j]);
printf("\n");
printf(" |");
for (j=1;j<=m;j++)
printf("\t%7.2f ",A[3][j]);
}
if (n==4){
printf("\n\n\n");
printf(" |");
for (j=1;j<=m;j++)
printf("\t%7.2f ",A[1][j]);
printf("\n");
printf(" |");
for (j=1;j<=m;j++)
printf("\t%7.2f ",A[2][j]);
printf("\n");
printf(" |");
for (j=1;j<=m;j++)
printf("\t%7.2f ",A[3][j]);
printf("\n");
printf(" |");
for (j=1;j<=m;j++)
printf("\t%7.2f ",A[4][j]);
}
cout<<endl;
cout<<endl;
for(i=1;i<=n;i++)
cout<<"X("<<i<<")= "<<A[i][m]<<endl;
getch();
}
}
No hay comentarios:
Publicar un comentario