Codigo fuente en C++
#include<cstdlib>
#include<stdio.h>
#include <time.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
int mat[20][20];
int c,p,k,s,i,j,dim;
//int MATRIX;
#define n 6
#define MATRIX 8
int magico6[100]={0,3,107,5,131,109,311,7,331,193,11,83,41,103,53,71,89,151,199,113,61,97,167,31,367,13,173,59,17,37,73,101,127,179,139,47,0};
int magico4[100]={0,3,107,5,131,109,311,7,331,193,11,83,41,103,53,71,89,151,199,113,61,97,167,31,367,13,173,59,17,37,73,101,127,179,139,47,0};
int origen[100]={0,0,107,5,131,109,311,7,331,193,11,83,41,103,53,71,89,151,199,113,61,97,167,31,367,13,173,59,17,37,73,101,127,179,139,47,0};
//int origen[100]={0,3,107,5,131,109,311,7,331,193,11,83,41,103,53,71,89,151,199,113,61,97,167,31,367,13,173,59,17,37,73,101,127,179,139,47,0};
//int magico4[100]={0,101,47,31,79,73,61,71,53,43,67,59,89,41,83,97,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int magico4a[100]={0,3,107,5,131,7,61,71,53,103,67,59,89,113,83,97,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
void dimencionar()
{
int dim,cu;
dim=n*n;
cu=0;
for (i=1; i<dim; i++)
{
if (cu==(dim/n)){
cout<<"\n";
cu=0;
}
origen[i]=magico4[i];
cout<<"\t"<<origen[i];
cu=cu+1;
}
cout<<"\n";
}
void original()
{
int dim,cu;
dim=n*n;
cu=0;
cout<<"\n";
for (i=0; i<dim; i++)
{
if (cu==(dim/n)){
cout<<"\n";
cu=0;
}
cout<<"\t"<<origen[i];
cu=cu+1;
}
cout<<"\n";
}
void imprimir()
{
cout<<"\n";
string cad [30][30] = {{"→"}, {"↑"}, {"►"}, {"↑"},{"↔"},{"←"},{"↨"}, {"▼"}, {"↓"},{"↑"},{"▼"},{"▲"},{"◄"},{"◘"}};
int a;
if (MATRIX==1)
{
a=0;
}
if (MATRIX==2)
{
a=1;
}
if (MATRIX==3)
{
a=2;
}
if (MATRIX==4)
{
a=3;
}
if (MATRIX==5)
{
a=4;
}
if (MATRIX==6)
{
a=5;
}
if (MATRIX==7)
{
a=6;
}
if (MATRIX==8)
{
a=7;
}
if (MATRIX==9)
{
a=8;
}
if (MATRIX==10)
{
a=9;
}
if (MATRIX==11)
{
a=10;
}
if (MATRIX==12)
{
a=11;
}
if (MATRIX==13)
{
a=12;
}
cout<<"Cuales son # Primos";
cout<<"\n";
int primos[100],k;
k=0;
for (i=0; i<=n-1;i++)
{
for (j=0;j<=n-1;j++)
{
cout<<"\t\t"<<mat[i][j];
int divisor = 1, divisores = 0, num = 0;
k=k+1;
num=mat[i][j];
do{
if(num % divisor == 0){
divisores++;
}
divisor++;
}while(divisor <= num);
if(divisores == 2){
cout<<"♣";
primos[k]=num;
}else{
cout<<"";
}
}
cout<<"\n";
}
}
void entrada_1( )
{
//original();
//Imprimir();
cout<<"ENTRADA N° (1) ";
cout<<"\n";
c=0;
s=0;
//*********************************************************************
//int divisor = 1, divisores = 0, num = 0;
//********************************************************/
for (i=0; i<=n-1; i++)
{
for (j=0; j<=n-1; j++)
{
s=s+1;
//algoritmo para primo
/////////////////////////////////////////
/////////////////////////////////
mat[i][j]=origen[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]=origen[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]=origen[s];
//cout<<"\t"<<mat[i][j];
c=c+1;
}
//cout<<"\n";
j=j+1;
}
}
}
void entrada_3()
{
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]=origen[s];
//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]=origen[s];
//cout<<"\t"<<mat[i][j];
c=c-1;
}
//cout<<"\n";
i=i+1;
}
}
}
void entrada_4()
{
//Imprimir();
cout<<"ENTRADA N° (4) ";
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=n-1; k>=0; k--)
{
s=s+1;
mat[k][j]=origen[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]=origen[s];
c=c+1;
//cout<<"\t"<<mat[i][j];
}
}
}
}
void entrada_5( )
{
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]=origen[s];
//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]=origen[s];
//cout<<"\t"<<mat[i][j];
c=c+1;
}
//cout<<"\n";
i=i+1;
}
}
}
void entrada_6()
{
//Imprimir();
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]=origen[s];
c=c+1;
//cout<<"\t"<<mat[i][j];
}
}
}
void entrada_7( )
{
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]=origen[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]=origen[s];
//cout<<"\t"<<mat[i][j];
c=c+1;
}
//cout<<"\n";
j=j-1;
}
}
}
void entrada_8()
{
//Imprimir();
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]=origen[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]=origen[s];
c=c+1;
//cout<<"\t"<<mat[i][j];
}
}
}
}
void entrada_9()
{
//Imprimir();
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]=origen[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]=origen[s];
c=c+1;
//cout<<"\t"<<mat[i][j];
}
}
}
}
void entrada_10()
{
//Imprimir();
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]=origen[s];
c=c+1;
//cout<<"\t"<<mat[i][j];
}
}
}
void entrada_12()
{
//Imprimir();
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]=s;
c=c+1;
//cout<<"\t"<<mat[i][j];
}
}
}
void entrada_13()
{
//Imprimir();
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]=s;
c=c+1;
//cout<<"\t"<<mat[i][j];
}
}
}
void entrada_11()
{
//Imprimir();
cout<<"ENTRADA N° (11) ";
cout<<"\n";
cout<<"----------------------------------------------------";
cout<<"\n";
//Imprimir();
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]=s;
c=c+1;
}
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];
}
}
}
}
int main(void)
{
cout<<"original";
original();
cout<<"Primos";
dimencionar();
//int MATRIX;
cout<<"N="<<n;
cout<<"\n";
//MATRIX=3;
if (MATRIX==1)
{
entrada_1();
}
if (MATRIX==2)
{
entrada_2();
}
if (MATRIX==3)
{
entrada_3();
}
if (MATRIX==4)
{
entrada_4();
}
if (MATRIX==5)
{
entrada_5();
}
if (MATRIX==6)
{
entrada_6();
}
if (MATRIX==7)
{
entrada_7();
}
if (MATRIX==8)
{
entrada_8();
}
if (MATRIX==9)
{
entrada_9();
}
if (MATRIX==10)
{
entrada_10();
}
if (MATRIX==11)
{
entrada_11();
}
if (MATRIX==12)
{
entrada_12();
}
if (MATRIX==13)
{
entrada_13();
}
//entrada_8();
//entrada_3();
// entrada_5();
//entrada_6();
//entrada_7();
//entrada_14();
//entrada_10();
//entrada_14();
//entrada_15();
imprimir();
}
No hay comentarios:
Publicar un comentario