sábado, 22 de diciembre de 2007
domingo, 9 de diciembre de 2007
SUMA Y MULTIPLICACION DE MATRICES
Program suma_multi;
Uses
winCrt;
Const
dim_max = 3;
Type
mat = array [1..dim_max , 1..dim_max] of real;
Var
mat_a,mat_b,mat_c : mat;
sumar,mult:boolean;
fil_a,fil_b,col_a,col_b :integer;
procedure inicio;
Var
contador : integer;
begin
ClrScr;
gotoxy(23,2);
WriteLn('SUMA Y MULTIPLICACION DE MATRICES');
for contador := 1 to 80 do
Write('');
writeln
end;
procedure dim ;
begin
WriteLn('MATRIZ A');
WriteLn;
Write('Número de filas ');
ReadLn(fil_a);
Write('Numero de columnas ');
ReadLn(col_a);
WriteLn;
WriteLn('MATRIZ B');
WriteLn;
Write('Número de filas ');
ReadLn(fil_b);
Write('Número de columnas ');
ReadLn(col_b)
end;
procedure compat_suma (fil_f_a,fil_f_b,col_f_a,col_f_b:integer;
Var bandera_f:boolean);
begin
if ((fil_f_a <> fil_f_b) or (col_f_a <> col_f_b)) then
begin
WriteLn;
WriteLn('Las matrices A y B no son iguales para la suma');
bandera_f :=false
end
else
bandera_f :=true
end;
procedure compat_mult(ren_f_a,ren_f_b,col_f_a,col_f_b:integer;
Var bandera_f:boolean);
begin
if col_f_a <> ren_f_b then
begin
WriteLn;
WriteLn('la columna no es igual ');
bandera_f := false
end
else
bandera_f := true
end;
procedure lee(nmat:char;Var mat_f:mat;ren_max,col_max:integer);
Var
ren,col : integer;
begin
WriteLn;
WriteLn('MATRIZ : ',nmat);
WriteLn;
for ren := 1 to ren_max do
for col := 1 to col_max do
begin
Write('Elemento [ ',ren,',',col,'] = ');
ReadLn(mat_f[ren,col])
end
end;
procedure suma( mat_f_a,mat_f_b:mat;Var mat_f_c:mat;
ren_f, col_f :integer);
Var
ren,col : integer;
begin
WriteLn;
WriteLn('sumatoria A y B es :');
for ren := 1 to ren_f do
for col := 1 to col_f do
mat_f_c[ren,col] := mat_f_a[ren,col] + mat_f_b[ren,col]
end;
procedure multiplica( mat_f_a, mat_f_b: mat ;Var mat_f_c : mat ;
ren_f_a, col_f_a, col_f_b :integer);
Var
ren, acol, bcol : integer ;
acum : real ;
begin
WriteLn;
WriteLn('multiplicacion de A y B es :');
for ren := 1 to ren_f_a do
for bcol := 1 to col_f_b do
begin
acum := 0.0 ;
for acol := 1 to col_f_a do
acum := acum + mat_f_a[ren,acol] * mat_f_b[acol,bcol];
mat_f_c[ren,bcol] := acum
end
end;
procedure imprime(nmat : char ; mat_f : mat ;
ren_f, col_f : integer) ;
Var
ren, col : integer;
begin
WriteLn;
WriteLn('MATRIZ ',nmat);
for ren := 1 to ren_f do
for col := 1 to col_f do
begin
Write(mat_f[ren,col]:6:1,' ');
WriteLn
end;
WriteLn;
Write('Oprima una tecla ');
ReadKey;
WriteLn
end;
begin
inicio;
dim;
compat_suma(fil_a,fil_b,col_a,col_b,sumar);
compat_mult(fil_a,fil_b,col_a,col_b,mult);
if sumar or mult then
begin
lee('A',mat_a,fil_a,col_a);
lee('B',mat_b,fil_b,col_b);
imprime('A',mat_a,fil_a,col_a);
imprime('B',mat_b,fil_b,col_b);
if sumar then
begin
suma(mat_a,mat_b,mat_c,fil_a,col_a);
imprime('C',mat_c,fil_a,col_b)
end;
if mult then
begin
multiplica(mat_a,mat_b,mat_c,fil_a,col_a,col_b);
imprime('D', mat_c, fil_a, col_b)
end
end
end.
Uses
winCrt;
Const
dim_max = 3;
Type
mat = array [1..dim_max , 1..dim_max] of real;
Var
mat_a,mat_b,mat_c : mat;
sumar,mult:boolean;
fil_a,fil_b,col_a,col_b :integer;
procedure inicio;
Var
contador : integer;
begin
ClrScr;
gotoxy(23,2);
WriteLn('SUMA Y MULTIPLICACION DE MATRICES');
for contador := 1 to 80 do
Write('');
writeln
end;
procedure dim ;
begin
WriteLn('MATRIZ A');
WriteLn;
Write('Número de filas ');
ReadLn(fil_a);
Write('Numero de columnas ');
ReadLn(col_a);
WriteLn;
WriteLn('MATRIZ B');
WriteLn;
Write('Número de filas ');
ReadLn(fil_b);
Write('Número de columnas ');
ReadLn(col_b)
end;
procedure compat_suma (fil_f_a,fil_f_b,col_f_a,col_f_b:integer;
Var bandera_f:boolean);
begin
if ((fil_f_a <> fil_f_b) or (col_f_a <> col_f_b)) then
begin
WriteLn;
WriteLn('Las matrices A y B no son iguales para la suma');
bandera_f :=false
end
else
bandera_f :=true
end;
procedure compat_mult(ren_f_a,ren_f_b,col_f_a,col_f_b:integer;
Var bandera_f:boolean);
begin
if col_f_a <> ren_f_b then
begin
WriteLn;
WriteLn('la columna no es igual ');
bandera_f := false
end
else
bandera_f := true
end;
procedure lee(nmat:char;Var mat_f:mat;ren_max,col_max:integer);
Var
ren,col : integer;
begin
WriteLn;
WriteLn('MATRIZ : ',nmat);
WriteLn;
for ren := 1 to ren_max do
for col := 1 to col_max do
begin
Write('Elemento [ ',ren,',',col,'] = ');
ReadLn(mat_f[ren,col])
end
end;
procedure suma( mat_f_a,mat_f_b:mat;Var mat_f_c:mat;
ren_f, col_f :integer);
Var
ren,col : integer;
begin
WriteLn;
WriteLn('sumatoria A y B es :');
for ren := 1 to ren_f do
for col := 1 to col_f do
mat_f_c[ren,col] := mat_f_a[ren,col] + mat_f_b[ren,col]
end;
procedure multiplica( mat_f_a, mat_f_b: mat ;Var mat_f_c : mat ;
ren_f_a, col_f_a, col_f_b :integer);
Var
ren, acol, bcol : integer ;
acum : real ;
begin
WriteLn;
WriteLn('multiplicacion de A y B es :');
for ren := 1 to ren_f_a do
for bcol := 1 to col_f_b do
begin
acum := 0.0 ;
for acol := 1 to col_f_a do
acum := acum + mat_f_a[ren,acol] * mat_f_b[acol,bcol];
mat_f_c[ren,bcol] := acum
end
end;
procedure imprime(nmat : char ; mat_f : mat ;
ren_f, col_f : integer) ;
Var
ren, col : integer;
begin
WriteLn;
WriteLn('MATRIZ ',nmat);
for ren := 1 to ren_f do
for col := 1 to col_f do
begin
Write(mat_f[ren,col]:6:1,' ');
WriteLn
end;
WriteLn;
Write('Oprima una tecla ');
ReadKey;
WriteLn
end;
begin
inicio;
dim;
compat_suma(fil_a,fil_b,col_a,col_b,sumar);
compat_mult(fil_a,fil_b,col_a,col_b,mult);
if sumar or mult then
begin
lee('A',mat_a,fil_a,col_a);
lee('B',mat_b,fil_b,col_b);
imprime('A',mat_a,fil_a,col_a);
imprime('B',mat_b,fil_b,col_b);
if sumar then
begin
suma(mat_a,mat_b,mat_c,fil_a,col_a);
imprime('C',mat_c,fil_a,col_b)
end;
if mult then
begin
multiplica(mat_a,mat_b,mat_c,fil_a,col_a,col_b);
imprime('D', mat_c, fil_a, col_b)
end
end
end.
PROGRAMA DE REGISTRO
PROGRAM cedula_notas;
Uses
winCrt;
Const
numalumnos = 5;
Type
tnotas = record
ci2 : longint;
n_parcial12,n_parcial2,n_parcial_1, n_par2: real;
end;
notas = Array[1..numalumnos] of tnotas;
var
clase : notas;
ci: longint;
n_parcial1, n_parcial, n_par, n_media: real;
i: Integer;
Begin
ClrScr;
For i := 1 to numalumnos Do
Begin
WRITE('Introduzca cedula del alumno ',i,' : ');
READLN(ci);
WRITE('Introduzca su nota parcial: ');
READLN(n_parcial1);
WRITE('Introduzca su nota parcial: ');
READLN(n_parcial);
WRITE('Introduzca su nota parcial : ');
READLN(n_par);
WRITELN;
With clase[i] Do
Begin
n_parcial12 := n_parcial1;
n_parcial2 :=n_parcial;
n_par2 := n_par;
ci2 := ci;
End;
End;
ClrScr;
WRITELN('C.i.':25,'Par1':8,'Parc2':8,'Parc3':8,'Media':8);
WRITELN;
For i := 1 to numalumnos do
With clase[i] do
Begin
n_media := (n_parcial12 + n_parcial2 + n_par2) / 3;
WRITE(ci2:25,n_parcial12:8:2,n_parcial2:8:2,n_par2:8:2);
WRITELN(n_media:8:2);
End;
End.
JONATHAN PABON
15756902 III SEMESTRE DE INFORMATICA
Uses
winCrt;
Const
numalumnos = 5;
Type
tnotas = record
ci2 : longint;
n_parcial12,n_parcial2,n_parcial_1, n_par2: real;
end;
notas = Array[1..numalumnos] of tnotas;
var
clase : notas;
ci: longint;
n_parcial1, n_parcial, n_par, n_media: real;
i: Integer;
Begin
ClrScr;
For i := 1 to numalumnos Do
Begin
WRITE('Introduzca cedula del alumno ',i,' : ');
READLN(ci);
WRITE('Introduzca su nota parcial: ');
READLN(n_parcial1);
WRITE('Introduzca su nota parcial: ');
READLN(n_parcial);
WRITE('Introduzca su nota parcial : ');
READLN(n_par);
WRITELN;
With clase[i] Do
Begin
n_parcial12 := n_parcial1;
n_parcial2 :=n_parcial;
n_par2 := n_par;
ci2 := ci;
End;
End;
ClrScr;
WRITELN('C.i.':25,'Par1':8,'Parc2':8,'Parc3':8,'Media':8);
WRITELN;
For i := 1 to numalumnos do
With clase[i] do
Begin
n_media := (n_parcial12 + n_parcial2 + n_par2) / 3;
WRITE(ci2:25,n_parcial12:8:2,n_parcial2:8:2,n_par2:8:2);
WRITELN(n_media:8:2);
End;
End.
JONATHAN PABON
15756902 III SEMESTRE DE INFORMATICA
lunes, 3 de diciembre de 2007
Suscribirse a:
Entradas (Atom)










