Sunteți pe pagina 1din 8

Escuela Politcnica Nacional

Facultad de Ciencias
Carrera de Ingeniera en Ciencias Econmicas y Financieras
Nombres:

Christopher Coral Barahona

Paralelo: Gr 2
Prof: Mat. Luis Guasgua.

1) Escribir un arreglo con los nmeros primos entre 1 y 100, el cual debe ser presentado
de forma ascendente y descendente
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int l=101;
int a[l]={};
for (int i=2; i<l; i++)
if(i%2!=0||i==2)
if(i%3!=0 || i==3)
if(i%5!=0 || i==5)
if(i%7!=0 || i==7)
a[i]=i;
cout<<"Ascendente"<<endl;
for(int j=2; j<l; j++)
if(a[j]!=0)
cout<<setw(2)<<a[j]<<" ";
cout<<endl;

cout<<"Descendente"<<endl;
for(int k=l-1; k>=2; k--)
if(a[k]!=0)
cout<<setw(2)<<a[k]<<" ";
cout<<endl;

2) Escribir un programa que lea 10 nmeros por el teclado, los guarde en un arreglo y
los presente en forma ascendente
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
const int l=10;
int a[l], n, in;
for (int i=0; i<l; i++)
{
cout<<"Ingrese su "<<i+1<<" numero: ";
cin>>n;
a[i]=n;
}
for(int z=0; z<l; z++)
cout<<a[z]<<" ";
cout<<endl;

for (int s=0; s<l;s++)


{
in=a[s];
int m=s;
while ((m>0)&&(a[m-1]>in))
{
a[m]=a[m-1];
m--;
}
a[m]=in;
}
cout<<"Arreglo Ordenado"<<endl;
for (int i=0; i<l; i++)
cout<<a[i]<<" ";
cout<<endl;
return 0;

3) Escribir que lea ingrese dos arreglos por el teclado uno de tamao 5 y uno de tamao
7 y luego presente en un solo arreglo pero el segundo multiplicado por 3.
#include <iostream>
using namespace std;
int main()
{
const int l=5, m=7, n=12;
int a[l], b[m], c[n];
for (int i=1; i<=l; i++)
{
cout<<"Ingrese primer arreglo su "<<i<<" numero: ";
cin>>a[i];
}
for (int j=1; j<=m; j++)
{
cout<<"Ingrese segundo arreglo su "<<j<<" numero: ";
cin>>b[j];
}
for (int x=1; x<=5; x++)
{
c[x]=a[x];
}
for (int y=6; y<=12; y++)
c[y]=3*b[y-5];
for(int z=1; z<=n; z++)
cout<<c[z]<<" ";
}

4) Ingrese un arreglo de tamao 10, luego indicar una posicin y presentar en pantalla
el nmero indicado.
#include <iostream>

using namespace std;


int main()
{
const int l=10;
int a[l];
int b;
for (int i=1; i<=l; i++)
{
cout<<"Ingrese su "<<i<<" numero: ";
cin>>a[i];
}
for(int j=1; j<=l; j++)
cout<<a[j]<<" ";
cout<<endl;
cout<<"Ingrese la posicion del numero que desee: ";
cin>>b;
}

cout<<"El numero es: "<<a[b]<<endl;

5) Elaborar un tablero de ajedrez donde los peones van con la P, las torres con la T, los
caballos con la C, los alfiles con la A, el rey con la R y la reina con M.
#include <iostream>
using namespace std;
int main()
{
char negro [5] = {' ',' ',' ',' ',' '};
char blanco [5] = {'*','*','*','*','*'};
char peonNegro [5] = {' ',' ','P',' ',' '};
char peonBlanco [5] = {'*','*','P','*','*'};
char V1[8] = {'T','C','A','M','R','A','C','T'};
char V2[8] = {'T','C','A','R','M','A','C','T'};
for (int u=0; u<8; u++)
{
if(u==0)
{
for (int t=0; t<5; t++)
{
if(t==2)
{
for (int r=0; r<8; r++)
{
if(r%2==0)
{
cout<<"**"<<V1[r]<<"**";
}
else
{
cout<<" "<<V1[r]<<" ";
}
}
}
else
for(int z=0; z<8; z++)
{
if(z%2==0)
for (int x=0; x<5; x++)
cout<<blanco[x];
else
for (int x=0; x<5; x++)
cout<<negro[x];
}
cout<<endl;
}
}
else if(u==6)
{
for (int b=0; b<5; b++)
{
if(b==2)
{

for(int a=0; a<4; a++)


{
for (int i=0; i<5; i++)
cout<<peonBlanco[i];
for (int j=0; j<5; j++)
cout<<peonNegro[j];
}
}
else
for(int a=0; a<4; a++)
{
for (int i=0; i<5; i++)
cout<<blanco[i];
for (int j=0; j<5; j++)
cout<<negro[j];
}
cout<<endl;
}
}
else if(u==1)
{
for (int b=0; b<5; b++)
{
if(b==2)
{
for(int a=0; a<4; a++)
{
for (int i=0; i<5; i++)
cout<<peonNegro[i];
for (int j=0; j<5; j++)
cout<<peonBlanco[j];
}
}
else
for(int a=0; a<4; a++)
{
for (int i=0; i<5; i++)
cout<<negro[i];
for (int j=0; j<5; j++)
cout<<blanco[j];
}
cout<<endl;
}
}
else if(u==7)
{
for (int t=0; t<5; t++)
{
if(t==2)
{
for (int r=0; r<8; r++)
{
if(r%2==0)
{

cout<<"

"<<V2[r]<<"

";

}
else
{

cout<<"**"<<V2[r]<<"**";

}
}
}
else
for(int z=0; z<8; z++)
{
if(z%2==0)
for (int x=0; x<5; x++)
cout<<negro[x];
else
for (int x=0; x<5; x++)
cout<<blanco[x];
}
cout<<endl;
}

}
else if(u%2==0)
for (int y=0; y<5; y++)
{
for (int z=0; z<8; z++)
{
if(z%2==0)
{
for (int x=0; x<5; x++)
cout<<blanco[x];
}
else
{
for (int x=0; x<5; x++)
cout<<negro[x];
}
}
cout<<endl;
}
else if (u%2!=0)
for (int y=0; y<5; y++)
{
for (int z=0; z<8; z++)
{
if(z%2==0)
{
for (int x=0; x<5; x++)
cout<<negro[x];
}
else
{
for (int x=0; x<5; x++)
cout<<blanco[x];
}

}
cout<<endl;
}
}
}

S-ar putea să vă placă și