#include <iostream>
#include<cstdlib>
#include<stdio.h>
#include <time.h>
#include <stdlib.h>
using namespace std;
int mat[20][20];
int c,p,k,s,i,j,dim;
//43 61 7
//1 37 73
//67 13 31
#define n 4
#define MATRIX 3
int filas=n;
int columnas=n;
int m3[3][3] = {{17,113,47},{89,59,29},{71,5,101}};
int m3a[3][3] = {{43,61,7},{1,37,73},{67,13,31}};
int m[6][6] = {{3,107,5,131,109,311},{7,331,193,11,83,41},{103,53,71,89,151,199},{113,61,97,197,167,31},{367,13,173,59,17,37},{73,101,127,179,139,47}};
int m4[4][4] = {{101,47,31,79},{73,61,71,53},{43,67,59,89},{41,83,97,37}};
void ingreso_magica()
{
for (int i = 0; i < filas; i++)
{
for (int j = 0; j < columnas; j++)
{
cout<<"\t"<<m[i][j];
}
cout<<"\n";
}
}
//int filas = (sizeof(m)/sizeof(m[0]));
//int columnas = (sizeof(m[0])/sizeof(m[0][0]));
void imprimir()
{
cout<<"\n";
cout<<"Numeros mayores a 100 ♣";
cout<<"\n";
s=0;
int k;
k=0;
for (i=0; i<=n-1;i++)
{
for (j=0;j<=n-1;j++)
{
cout<<"\t"<<mat[i][j];
if (mat[i][j]>100)
{
cout<<"♣";
}
}
cout<<"\n";
}
int sc;
cout<<"\n";
sc=0;
j=0;
cout<<"Columna:"<<j+1;
for (i=0; i<n; i++)
{
sc=sc+mat[i][j];
cout<<"\t"<<mat[i][j];
}
cout<<" Suma es:"<<sc;
int sf;
cout<<"\n";
i=0;
sf=0;
cout<<"Fila:"<<i+1<<"\t";
for (j=0; j<n; j++)
{
sf=sf+mat[i][j];
cout<<"\t"<<mat[0][j];
}
cout<<" Suma es: "<<sf;
int sd1,sd2;
sd1=0;
sd2=0;
//cout<<"\nDiagonal 1";
cout<<"\nDiagonal 1: "<<"\t"<<mat[0][0]<<"\t"<<mat[1][1]<<"\t"<<mat[2][2]<<"\t"<<mat[3][3]<<"\t"<<mat[4][4]<<"\t"<<mat[5][5];
for (i=0;i<=n;i++)
{
for(j=i;j<=i;j++)
sd1=sd1+mat[i][j];
}
cout<<" Suma es de:"<<sd1;
//cout<<"\nDiagonal 2";
cout<<"\nDiagonal 2:"<<"\t"<<mat[0][5]<<"\t"<<mat[1][4]<<"\t"<<mat[2][3]<<"\t"<<mat[3][2]<<"\t"<<mat[4][1]<<"\t"<<mat[5][0];
for (j=n;j>=0;j--)
{
for(i=j;i==j;i--)
sd2=sd2+mat[i][j];
//cout<<"\t"<<mat[i][j];
}
cout<<" Suma es de:"<<sd2;
if (sc==sf){cout<<"\nMATRIX MAGICA";}
else {cout<<"\nMATRIX con Numeros Compuesto Positivos";}
}
void ingreso_magica3()
{
for (int i = 0; i < filas; i++)
{
for (int j = 0; j < columnas; j++)
{
cout<<"\t"<<m3[i][j];
m[i][j]=m3[i][j];
}
cout<<"\n";
}
}
void ingreso_magica4()
{
for (int i = 0; i < filas; i++)
{
for (int j = 0; j < columnas; j++)
{
cout<<"\t"<<m4[i][j];
m[i][j]=m4[i][j];
}
cout<<"\n";
}
}
void entrada_1( )
{
if (n==3)
{
ingreso_magica3();
}
if (n==4)
{
ingreso_magica4();
}
if (n==6)
{
ingreso_magica();
}
cout<<"ENTRADA N° (1) ";
cout<<"\n";
c=0;
s=0;
cout<<"\n\t";
//*********************************************************************
// int divisor = 1, divisores = 0, num = 0;
s=0;
//******************************************************
int co;
for (i=0; i<=n-1; i++)
{
co=0;
for (j=0; j<=n-1; j++)
{
if (co<=n-1)
{
co=co+1;
s=s+mat[i][j];
}
mat[i][j]=m[i][j];
//mat[i][j]=s;
c=c+1;
//cout<<"\t→"<<mat[i][j];
}
}
}
void entrada_2( )
{
cout<<"ENTRADA N° 2 ";
cout<<"\n";
c=n;
s=0;
dim=(n*n)-1;
i=0;
k=0;
//cout<<"\nn="<<n;
for (k=0; k<=n; k++)
{
//cout<<"\nc="<<c;
if (c==n)
{
for (i=n-1; i>=0; i--)
{
s=s+1;
mat[i][j]=m[i][j];
//cout<<"\t"<<mat[i][j];
c=c-1;
}
j=j+1;
}
if (c==0)
{
for (i=0; i<=n-1;i++)
{
s=s+1;
mat[i][j]=s;
//cout<<"\t"<<mat[i][j];
c=c+1;
}
//cout<<"\n";
j=j+1;
}
}
}
void entrada_3()
{
if (n==3)
{
ingreso_magica3();
}
if (n==4)
{
ingreso_magica4();
}
if (n==6)
{
ingreso_magica();
}
cout<<"ENTRADA N° 3 ";
cout<<"\n";
//n=9;
c=0;
s=0;
dim=(n*n)-1;
i=0;
//cout<<"\nn="<<n;
for (k=0; k<=n; k++)
{
if (c==0)
{
for (j=0; j<=(n-1); j++)
{
//s=s+1;
mat[i][j]=m[i][j];
//cout<<"\t"<<mat[i][j];
c=c+1;
}
i=i+1;
}
if (c==(n))
{
//cout<<"\n";
//i=i+1;
for (j=n-1; j>=0;j--)
{
//s=s+1;
mat[i][j]=m[i][j];
//cout<<"\t"<<mat[i][j];
c=c-1;
}
//cout<<"\n";
i=i+1;
}
}
}
void entrada_4()
{
if (n==3)
{
ingreso_magica3();
}
if (n==4)
{
ingreso_magica4();
}
if (n==6)
{
ingreso_magica();
}
cout<<"ENTRADA N° (4) ";
cout<<"\n";
c=0;
s=0;
for (j=0; j<=n-1; j++)
{
if (c==n)
{
for (k=n-1; k>=0; k--){
s=s+1;
mat[k][j]=m[k][j];
c=c+1;}
c=c-n;
}
if (c==0)
{
for (i=0; i<=n-1; i++)
{
mat[i][j]=m[i][j];
c=c+1;
}
}
}
}
void entrada_5( )
{
ingreso_magica();
cout<<"ENTRADA N° 5 ";
cout<<"\n";
c=n;
s=0;
dim=(n*n)-1;
i=0;
k=0;
//cout<<"\nn="<<n;
for (k=0; k<=n; k++)
{
//cout<<"\nc="<<c;
if (c==n)
{
for (j=n-1; j>=0; j--)
{
s=s+1;
mat[i][j]=m[i][j];
//cout<<"\t"<<mat[i][j];
c=c-1;
}
i=i+1;
}
if (c==0)
{
for (j=0; j<=n-1;j++)
{
s=s+1;
mat[i][j]=m[i][j];
//cout<<"\t"<<mat[i][j];
c=c+1;
}
//cout<<"\n";
i=i+1;
}
}
}
void entrada_6()
{
ingreso_magica();
cout<<"ENTRADA N° (6) ";
cout<<"\n";
c=0;
s=0;
for (i=0; i<=n; i++)
{
if (c==n)
{
//cout<<"c="<<c<<"n"<<n<<"i"<<i<<"="<<mat[0][1];
}
for (j=n-1; j>=0; j--)
{
s=s+1;
mat[i][j]=s;
c=c+1;
//cout<<"\t"<<mat[i][j];
}
}
}
void entrada_7( )
{
ingreso_magica();
cout<<"ENTRADA N° 7 ";
cout<<"\n";
c=n;
s=-n;
dim=(n*n)-1;
i=0;
k=0;
j=n;
//cout<<"\nn="<<n;
for (k=0; k<=n; k++)
{
//cout<<"\nc="<<c;
if (c==n)
{
for (i=n-1; i>=0; i--)
{
s=s+1;
mat[i][j]=s;
//cout<<"\t"<<mat[i][j];
c=c-1;
}
j=j-1;
}
if (c==0)
{
for (i=0; i<=n-1;i++)
{
s=s+1;
mat[i][j]=s;
//cout<<"\t"<<mat[i][j];
c=c+1;
}
//cout<<"\n";
j=j-1;
}
}
}
void entrada_8()
{
//Imprimir();
ingreso_magica();
cout<<"ENTRADA N° (8) ";
cout<<"\n";
c=0;
s=-n;
for (j=n; j>=0; j--)
{
//cout<<"\n"<<c;
if (c==n)
{
// k=k+1;
//k=i;
//cout<<"c="<<c<<"n"<<n<<"i"<<i<<"="<<mat[0][1];
for (k=0; k<=n-1; k++)
{
s=s+1;
mat[k][j]=s;
c=c+1;
//cout<<"\t"<<mat[i][j];
}
c=c-n;
}
if (c==0)
{
for (i=0; i<=n-1; i++)
{
s=s+1;
mat[i][j]=s;
c=c+1;
//cout<<"\t"<<mat[i][j];
}
}
}
}
void entrada_9()
{
ingreso_magica();
cout<<"ENTRADA N° (9) ";
cout<<"\n";
c=0;
s=0;
for (j=0; j<=n-1; j++)
{
//cout<<"\n"<<c;
if (c==n)
{
// k=k+1;
//k=i;
//cout<<"c="<<c<<"n"<<n<<"i"<<i<<"="<<mat[0][1];
for (k=0; k<=n-1; k++)
{
s=s+1;
mat[k][j]=s;
c=c+1;
//cout<<"\t"<<mat[i][j];
}
c=c-n;
}
if (c==0)
{
for (i=0; i<=n-1; i++)
{
s=s+1;
mat[i][j]=s;
c=c+1;
//cout<<"\t"<<mat[i][j];
}
}
}
}
void entrada_10()
{
ingreso_magica();
cout<<"ENTRADA N° (10) ";
cout<<"\n";
c=0;
s=0;
for (j=0; j<=n; j++)
{
if (c==n)
{
//cout<<"c="<<c<<"n"<<n<<"i"<<i<<"="<<mat[0][1];
}
for (i=n-1; i>=0; i--)
{
s=s+1;
mat[i][j]=m[i][j];
c=c+1;
//cout<<"\t"<<mat[i][j];
}
}
}
void entrada_12()
{
ingreso_magica();
cout<<"ENTRADA N° (12) ";
cout<<"\n";
c=0;
s=0;
for (j=n-1; j>=0; j--)
{
if (c==n)
{
//cout<<"c="<<c<<"n"<<n<<"i"<<i<<"="<<mat[0][1];
}
for (i=n-1; i>=0; i--)
{
s=s+1;
mat[i][j]=m[i][j];
c=c+1;
//cout<<"\t"<<mat[i][j];
}
}
}
void entrada_13()
{
ingreso_magica();
cout<<"ENTRADA N° (13) ";
cout<<"\n";
cout<<"----------------------------------------------------";
cout<<"\n";
c=0;
s=0;
for (i=n-1; i>=0; i--)
{
if (c==n)
{
//cout<<"c="<<c<<"n"<<n<<"i"<<i<<"="<<mat[0][1];
}
for (j=n-1; j>=0; j--)
{
s=s+1;
mat[i][j]=m[i][j];
c=c+1;
}
}
}
void entrada_11()
{ ingreso_magica();
cout<<"ENTRADA N° (11) ";
cout<<"\n";
cout<<"----------------------------------------------------";
cout<<"\n";
c=0;
s=0;
for (j=n-1; j>=0; j--)
{
//cout<<"\n"<<c;
if (c==n)
{
for (k=n-1; k>=0; k--)
{
s=s+1;
mat[k][j]=m[k][j];
c=c+1;
}
c=c-n;
}
if (c==0)
{
for (i=0; i<=n-1; i++)
{
s=s+1;
mat[i][j]=m[i][j];
c=c+1;
}
}
}
}
int main(void)
{
cout<<"Docente Nestor Orlando Calderon: N="<<n;
cout<<"\n";
if (MATRIX==1) {entrada_1();}if (MATRIX==3) {entrada_3();}if (MATRIX==4) {entrada_4();}if (MATRIX==5) {entrada_5();}
if (MATRIX==10){entrada_10();} if (MATRIX==11){entrada_11();} if (MATRIX==12){entrada_12();}
if (MATRIX==13) {entrada_13();}
if (MATRIX==2) {entrada_2();}if (MATRIX==6) {entrada_6();}if (MATRIX==7) {entrada_7();}if (MATRIX==8) {entrada_8();}
if (MATRIX==9) {entrada_9();}
imprimir();
}
No hay comentarios:
Publicar un comentario