You are on page 1of 4

EJERCICIO 8

clc
f=input('Ingrese el nmero de filas:');
c=input('Ingrese el nmero de columnas:');
for i=1:f
for j=1:c
fprintf('m(%d,%d):',i,j)
m(i,j)=input('');
end
end
n=f/2;
t=fix(f/2);
p=f+1;
for i=1:f
for j=1:c
if rem(f,2)==0
for y=1:n

m(i,j)=m(p,j);
p=p-1;
fprintf('%f\n',m(p,j));
end
else
for y=1:t

m(i,j)=m(p,j);
p=p-1;
fprintf('%f\n',m(c,j));
end
end

end

end

EJERCICIO 11:
clear all
clc
f=input('Ingrese el nmero de filas:');
c=input('Ingrese el nmero de columnas:');
for i=1:f
for j=1:c
fprintf('m(%d,%d):',i,j)
m(i,j)=input('');
end
end
for j=1:c
if rem(j,2)==0
for i=f:-1:1
fprintf('%f\n',m(i,j));
end
else
for i=1:f
fprintf('%f\n',m(i,j));
end
end
fprintf('\n');
end

EJERCICIO 12:

clear all
clc
n=input('Orden de la matriz:');
for i=1:n
for j=1:n
fprintf('m(%d,%d):',i,j)
m(i,j)=input('');
end
end
s=0;
for i=1:n
for j=1:n
if i==j
s=s+m(i,j);
end
end
end
fprintf('La suma de los elementos de la diagonal principal es : %f\n',s);
t=0;
c=0;
for i=1:n
for j=1:n
if i+j==n+1
t=t+m(i,j);
c=c+1;
end
end
end
ps=t/c;
fprintf('La suma de los elementos de la diagonal secundaria es :
%f\n',ps);
disp('La matriz principal ');
for i=1:n
for j=1:n
if i==j
fprintf('%f\n',m(i,j));
end
fprintf('\n');
end
end
disp('La matriz secundaria ');
for i=1:n
for j=1:n
if i+j==n+1
fprintf('%f\n',m(i,j));
end
fprintf('\n');
end
end

CUBO MAGICO:

clear all
clc
n=input('Ingrese el orden de la matriz:');
valor=1;
i=1;
j=fix(n/2)+1;
while valor <=n*n
m(i,j)=valor;
if rem (valor,n)==0
if i==n
i=1;
else
i=i+1;
end
else
if i==1
i=n;
else
i=i-1;
end
if j==n
j=1;
else
j=j+1;
end
end
valor=valor+1;
end
fprintf('n\');

You might also like