miércoles, 14 de marzo de 2012

Calculo de la matriz TRASPUESTA

Programa muy sencillo para calcular la traspuesta de una matriz:

program TRASPUESTA(input,output);

const
  MaxDim=100;

type
  Matriz=record
    fil:integer;
    col:integer;
    comp:array[1..MaxDim,1..MaxDim] of real;
  end;
  tpContador=1..MaxDim;

var
  M,T:Matriz;

procedure CargaDatos(VAR M:Matriz);
  var
    i,j:tpContador;
  begin
    writeln;writeln('VISITANOS EN:   http://www.matematicapascal.blogspot.com/');writeln;
    writeln;writeln('Calcula la traspuesta de una matriz.');writeln;
    write('Introduzca el numero de filas: ');readln(M.fil);
    write('Introduzca el numero de columnas: ');readln(M.col);
    for i:=1 to M.fil do begin
      for j:=1 to M.col do begin
        write('Introduzca M(',i,',',j,'): '); readln(M.comp[i,j])
      end;
      writeln
    end
  end;

procedure CalcTraspuesta(VAR T:Matriz; M:Matriz);
  var
    i,j:tpContador;
  begin
    T.col:=M.fil;
    T.fil:=M.col;
    for i:=1 to T.fil do
      for j:=1 to T.col do
        T.comp[i,j]:=M.comp[j,i]
  end;

procedure EscribeMatriz(M,T:Matriz);
  var
    i,j:tpContador;
  begin
    writeln('La matriz introducida es: ');
    for i:=1 to M.fil do begin
      for j:=1 to M.col do
        write(M.comp[i,j]:7:3);
      writeln
    end;
    writeln('La matriz traspuesta es: ');
    for i:=1 to T.fil do begin
      for j:=1 to T.col do
        write(T.comp[i,j]:7:3);
      writeln
    end
  end;

begin
  CargaDatos(M);
  CalcTraspuesta(T,M);
  EscribeMatriz(M,T);
  readln
end.








Salud!!

No hay comentarios:

Publicar un comentario