Club Delphi  
    Paypal   FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros entornos y lenguajes > Lazarus, FreePascal, Kylix, etc.
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 07-01-2012
RadamantiS RadamantiS is offline
Registrado
NULL
 
Registrado: ene 2012
Posts: 8
Poder: 0
RadamantiS Va por buen camino
Respecto a tu respuesta Maxium, no pretendo que me lo hagan, básicamente porque a parte de mi TAREA también tendré un examen, y en ese examen no creo que me pueda meter aquí para que me lo hagan.
Si pretendes ayudarme, muchas gracias. Pero si lo que pretendes es que haya mal rollo es este tema, mejor no respondas más.
Responder Con Cita
  #2  
Antiguo 07-01-2012
Avatar de Casimiro Noteví
Casimiro Noteví Casimiro Noteví is offline
Merodeador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.682
Poder: 10
Casimiro Noteví Tiene un aura espectacularCasimiro Noteví Tiene un aura espectacular
RadamantiS, ¿ya leiste nuestra guía de estilo?, gracias por tu colaboración.

No olvides poner etiquetas al código, ejemplo:



.
Responder Con Cita
  #3  
Antiguo 15-01-2012
RadamantiS RadamantiS is offline
Registrado
NULL
 
Registrado: ene 2012
Posts: 8
Poder: 0
RadamantiS Va por buen camino
Hola, ya tengo hecho todo, pero cuando ejecuto el programa no me saca los elementos mayor y menor de la matriz bien, ni me hace el intercambio entre ambos elementos. Los procedimientos que he empleado son los siguientes:
CONST
max=10;
mm=10;
TYPE
matriz=ARRAY[1..mm,1..max] OF integer;
VAR {Estas son las variables del programa principal}
mat,mat1,mat2:matriz;
lado_i,lado_j:integer;
i,j:integer;
n_mayor,n_menor:integer;
p_mayor,p_menor:ARRAY[1..2] OF integer;

procedure mayor_menor_matriz(var n_mayor,n_menor:integer);
var
mat:matriz;
begin
leer_matriz(lado_i,lado_j,mat);
FOR i:=1 TO mm DO
n_mayor:=mat[1,1];
n_menor:=mat[1,1];
FOR i:=1 TO mm DO
FOR j:=1 TO max DO
IF mat[i,j]>n_mayor THEN
begin
n_mayor:=mat[i,j];
p_mayor[2]:=j;
p_mayor[1]:=i;
end;
IF mat[i,j]<n_menor THEN
begin
n_menor:=mat[i,j];
p_menor[2]:=j;
p_menor[1]:=i;
end;
writeln ('El menor elemento es ',n_menor);
writeln ('El mayor es ',n_mayor);
readln;
end;

procedure intercambio_matriz(var n_mayor,n_menor:integer;mat:matriz);
var
nmenor,nmayor:integer;
i,j:integer;
mat_inter:matriz;
begin
mat_inter:=mat;
mayor_menor_matriz(n_mayor,n_menor);
nmenor:=n_menor;
nmayor:=n_mayor;
FOR i:=1 TO lado_i DO
FOR j:=1 TO lado_j DO
begin
IF nmenor=mat[i,j] THEN mat_inter[i,j]:=nmayor;
IF nmayor=mat[i,j] THEN mat_inter[i,j]:=nmenor;
end;
Mostrar_matriz (mat_inter,lado_i,lado_j);
readln;

Muchas gracias!
P.D.: Al final me dieron una semana más para entregarlo
Responder Con Cita
  #4  
Antiguo 15-01-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola RadamantiS.

¿ No leiste el mensaje #14 de Casimiro ?, creo que es muy claro: Cuando incluyas código en tus mensajes, enciérralo entre las etiquetas correspondientes.

Saludos y gracias por tu colaboración.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #5  
Antiguo 15-01-2012
RadamantiS RadamantiS is offline
Registrado
NULL
 
Registrado: ene 2012
Posts: 8
Poder: 0
RadamantiS Va por buen camino
Código Delphi [-]
CONST
  max=10;
  mm=10;
TYPE
  matriz=ARRAY[1..mm,1..max] OF integer;
VAR  {Estas son las variables del programa principal}
  mat,mat1,mat2:matriz;
  lado_i,lado_j:integer;
  i,j:integer;
  n_mayor,n_menor:integer;
  p_mayor,p_menor:ARRAY[1..2] OF integer;                

procedure mayor_menor_matriz(var n_mayor,n_menor:integer);
var
mat:matriz;
begin
leer_matriz(lado_i,lado_j,mat);
FOR i:=1 TO mm DO
n_mayor:=mat[1,1];
n_menor:=mat[1,1];
FOR i:=1 TO mm DO
FOR j:=1 TO max DO
IF mat[i,j]>n_mayor THEN
begin
n_mayor:=mat[i,j];
p_mayor[2]:=j;
p_mayor[1]:=i;
end;
IF mat[i,j]THEN
begin
n_menor:=mat[i,j];
p_menor[2]:=j;
p_menor[1]:=i;
end;
writeln ('El menor elemento es ',n_menor);
writeln ('El mayor es ',n_mayor);
readln;
end;

procedure intercambio_matriz(var n_mayor,n_menor:integer;mat:matriz);
var
nmenor,nmayor:integer;
i,j:integer;
mat_inter:matriz;
begin
mat_inter:=mat;
mayor_menor_matriz(n_mayor,n_menor);
nmenor:=n_menor;
nmayor:=n_mayor;
FOR i:=1 TO lado_i DO
FOR j:=1 TO lado_j DO
begin
IF nmenor=mat[i,j] THEN mat_inter[i,j]:=nmayor;
IF nmayor=mat[i,j] THEN mat_inter[i,j]:=nmenor;
end;
Mostrar_matriz (mat_inter,lado_i,lado_j);
readln;
Responder Con Cita
  #6  
Antiguo 15-01-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 38
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola RadamantiS.

No me queda bién en claro si deseas cambiar los valores de las variables máximo y mínimo, en cuyo caso es tan simple como:
Código Delphi [-]
var
  aux: Integer;
begin
  aux:= Minimo;
  Minimo:= Maximo;
  Maximo:= aux;
  ...
o deseas que intercambien las posiciciones dentro de la matriz. Si este último es el caso, te hice un ejemplo muy simple para que te sirva de guía:
Código Delphi [-]
program Project1; {$APPTYPE CONSOLE}

uses
  SysUtils, Types;

const
  MAX_FIL = 5;
  MAX_COL = 5;

type
  TMatrix = array[1..MAX_FIL, 1..MAX_COL] of Integer;

(* Carga valores aleatorios *)
procedure LoadMatrix(var mat: TMatrix);
var
  f,c: Integer;
begin
  Randomize;
  for f:= 1 to 5 do
   for c:= 1 to 5 do
     mat[f,c]:= Random(100);
end;

(* Mostrar valores de matriz *)
procedure ShowMatrix(Mat: TMatrix);
var
  f,c: Integer;
begin
  Randomize;
  for f:= 1 to 5 do
  begin
    for c:= 1 to 5 do
      Write(mat[f,c]:3);
    writeln;
  end;
end;

(* devuelve posiciones de valores mínimo y máximo en Result *)
function MaxMinValues(Mat: TMatrix; var Mayor, Menor:integer): TRect; 
var
  f, c: Integer;
begin
  Mayor:= mat[1,1];
  Menor:= mat[1,1];
  for f:= 1 to  MAX_FIL do
    for c:= 1 to MAX_COL do
      if mat[f,c] < Menor then
      begin
        Menor:= Mat[f,c];
        Result.Left:= f;   // fila valor mínimo
        Result.Top:= c;  //  columna valor mínimo
      end
      else if Mat[f,c] > Mayor then
      begin
        Mayor:= Mat[f,c];
        Result.Right:= f;    // fila valor máximo
        Result.Bottom:= c; // columna valor máximo
      end;
end;

(* Intercambia posiciones de valores mínimo y máximo *)
procedure SwapValues(var Mat: TMatrix; T: TRect);
var
  aux: Integer;
begin
  aux:= Mat[T.Left,T.Top];
  Mat[T.Left,T.Top]:= Mat[T.Right, T.Bottom];
  Mat[T.Right, T.Bottom]:= aux;
end;

(* main *)
var
  May, Min: Integer;
  Mat: TMatrix;
  T: TRect;
begin
  LoadMatrix(Mat);
  Writeln('Carga inicial:');
  ShowMatrix(Mat);
  T:= MaxMinValues(Mat, May, Min);
  writeln (#10,'Menor elemento: ',Min,' Mayor elemento: ',May,#10);
  Writeln('Valores intercambiados');
  SwapValues(Mat, T);
  ShowMatrix(Mat);
  Readln;
end.
Ahora bién, hay que tomar en cuenta que al cargarse de forma aleatoria puede haber repetición de valores. Es decir que si en la matriz tenemos duplicados los valores mínimos y máximos posibles (en el ejemplo 0 y 99), sólo se hará un intercambio.


Un saludo.

Edito: Dos comentarios, no olvides incluir Types en la cláusula uses. La función MaxMinValues bién podría prescindir de los argumentos por referencia Mayor y Menor, pero los dejé por si necesitas utilizar su valor en otra parte del programa.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....

Última edición por ecfisa fecha: 15-01-2012 a las 19:36:07.
Responder Con Cita
  #7  
Antiguo 15-01-2012
RadamantiS RadamantiS is offline
Registrado
NULL
 
Registrado: ene 2012
Posts: 8
Poder: 0
RadamantiS Va por buen camino
Muchísimas gracias!!
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Comparativa entre Free Pascal 2.2.0 y Turbo Pascal 7.0 esocrates Varios 2 14-07-2008 14:56:24
crear un programa tipo pascal que funcione con el disco de inicio ms-dos kurono Varios 5 14-03-2008 22:28:17
Calculadora sebaguillen Varios 17 28-08-2007 15:27:23
Calculadora Epunamun OOP 3 19-12-2005 22:33:11
manual de excepciones de object pascal para free pascal??? Garion OOP 3 27-05-2005 00:42:29


La franja horaria es GMT +2. Ahora son las 03:12:24.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi