Sei sulla pagina 1di 13

Saavedra cardenas alther 20110144 A.

// para segunda.cpp: define el punto de entrada de la aplicación de consola.


//

////Halla la suma de una serie con while


/*Su=(A-2B)/(A^(1/(2i-1))-(3A-4B)/(

#include "stdafx.h"
#include "iostream"
#include "math.h"
#include "stdlib.h"
#include "time.h"

#define mensaje "\n Otra Prueba[S][N] "

using namespace std;


void main()
{srand((unsigned)time(NULL));
int A,B,i=1,N;double Su=0;char rp;
for(;;){system("cls");Su=0;
A=rand()%50;
cout<<"El Valor de A = "<<A<<endl;
B=rand()%50;
cout<<"El Valor de B = "<<B<<endl;
N=rand()%100;
cout<<"El No de Terminos N = "<<N<<endl;
if(A==0)
cout<<"\n No existe Solucion ";
else
while(i<=N){
Su+=(powf((-1),i+1)*((2*i-1)*A-(2*i)*B))/(powf(A,(1.0/(2*i-1))));
i++;
}
cout<<"La suma = "<<Su<<endl;
cout<<mensaje;
cin>>rp;
if(rp=='N')break;}
system("pause");
}*/

/*
//HALLAR S=1-2!/2^1/2 + 3!/3^1/2 - 4!/4^1/2 + 5!/5^1/2 ...

#include "stdafx.h"
#include "iostream"
#include "math.h"
#include "stdlib.h"
#include "time.h"

#define mensaje "otra pueba[S][N]"

using namespace std;

void main(){
srand((unsigned)time(NULL));
float a,b,c,u,i,F;
double s,n;
char rp;
cout<<"\n el numero de terminos es: ";cin>>n;
for(;;){
s=0;
i=1;
F=1;
//n=rand()%9;
while(i<=n)
{ F=F*i;
s=s+powf(-1,i+1)*F/powf(i,1.0000000000000/2);
i++;
//cout<<"\n el valor de s es: "<<s<<endl;
}

cout<<"\n el valor de n es: "<<n<<endl;


cout<<"\n el valor de s es: "<<s<<endl;
cout<<mensaje;
cin>>rp;
if(rp=='N') break;
else
{if(rp=='S')
cout<<"\n el numero de terminos es: ";cin>>n;} }
system("pause");
} */

/*
//Invertir el orden de cifras de un número cualquiera.
#include "stdafx.h"
#include "math.h"
#include "iostream"
#include "stdlib.h"
#include "time.h"
#define mensaje "Otra prueba [S][N]: "

using namespace std;

void main(){
srand((unsigned)time(NULL));
int a,s=0,b,i,c;
char rp;
//cout<<"\n introducir el numero: ";cin>>a
for(;;){
a=rand()%100001;
c=a;
s=0;
cout<<"\n el número es: "<<a<<endl;
do{
b=c%10;
c=c/10;
s=10*s+b;
}
while(c/10!=0);
s=s*10+c;
cout<<"\n el numero invertido es: "<<s<<endl;

cout<<mensaje;
cin>>rp;
if(rp=='N') break;}

system("pause");

}*/

/*
//suma de s1 - 3^1/3 + 5^1/5 - 7^1/7+ ...
//suma de s2 - 3/2!^1/2 + 5/3!^1/2 - 7/4!^1/2+ ...
#include "stdafx.h"
#include "stdlib.h"
#include "iostream"
#include "math.h"
#include "time.h"

#define mensaje " otra prueba [S][N]: "

using namespace std;

void main(){
int N;
float s1=0,s2=0,i,F=1;
char rp;
cout<<"\n sumar para cierto n las expresiones"<<endl
<<" s1=1 - 3^1/3 + 5^1/5 - 7^1/7 + ..."<<endl
<<" s2=1 - 3/2!^1/2 + 5/3!^1/2 - 7/4!^1/2+ ..."<<endl;
for(;;)
{float s1=0,s2=0,i,F=1;
cout<<"\n ingresar numero de termino: ";cin>>N;

for(i=0;i<=N;i++)
{ F=F*(i+1);

s1=s1+powf(-1,i)*1.0*powf(2*i+1,1.0*1/(2*i+1));

s2=s2+powf(-1,i)*(2*i+1)*1.0/(sqrtf(F));}
cout<<"\ las sumas respectivas son: "<<s1<<"; "<<s2<<endl;
cout<<mensaje;
cin>>rp;
if(rp=='N') break;}

system("pause");
}
*/
//Arreglos;
/*
//Creando Una Matriz
#include"stdafx.h"
#include<iostream>
#include<stdlib.h>
#include<time.h>
#include<iomanip>
using namespace std;
void main(){
srand((unsigned)time(NULL));
int fil,col,Ma[100][100],indi,indj,i,j,Mayo;
cout<<"Ingrese el Tamaño de la Fila= ";
cin>>fil;
cout<<"Ingrese el Tamaño de la Columna= ";
cin>>col;
for(i=0;i<fil;i++)
for(j=0;j<col;j++)
Ma[i][j]=rand()%21;
cout<<"Los Valores Generados son= \n";
for(i=0;i<fil;i++){
for(j=0;j<col;j++){
cout<<setw(4)<<Ma[i][j]<<' ';}
cout<<endl;
}
cout<<endl<<endl;
//Ma[2][3]=100;
for(i=0;i<fil;i++){
for(j=0;j<col;j++){
cout<<setw(4)<<Ma[i][j]<<' ';}
cout<<endl;
}
Mayo=Ma[0][0];
for(i=0;i<fil;i++)
for(j=0;j<col;j++)
if(Ma[i][j]>=Mayo){
Mayo=Ma[i][j];
indi=i;
indj=j;
}
cout<<"\nEl Mayor Valor es "<<Mayo<<"\nUbicado en
["<<indi<<']'<<'['<<indj<<']'<<endl;
system("pause");
}
*/

//crea una matriz de


/*
#include "stdafx.h"
#include "iostream"
#include "time.h"
#include "math.h"
#include "stdlib.h"
#include "iomanip"

using namespace std;

void main(){

int i,j,a,b,c,d,e,matriz[5][5];

for(i=0;i<1;i++)
for(j=0;j<5;j++)

matriz[i][j]=powf(i,2)+j*j;

cout<<setw(4)<<matriz[0][4]<<' '<<endl;

cout<<" Los valores generados son=\n";

for(i=0;i<1;i++)
{for(j=0;j<5;j++){
cout<<setw(4)<<matriz[i][j]<<' ';}

cout<<endl;}

system("pause");
}
*/
//halla asi es la cuestión.

//sea 13,17,85,6,10,15
/*Hallar
a) el mayor lugar.
b) el menor lugar.
c) el Promedio.
d) cuantos superan el promedio.
e) ordenarlas.
*/
#include "stdafx.h"
#include "iostream"
#include "math.h"
#include "stdlib.h"
#include "iomanip"
#include "time.h"

using namespace std;

void main(){
int a,b,c,i,j,h,u,num[100],ord[100],menor,mayor;
float pro;
num[0]=13;
num[1]=17;
num[2]=85;
num[3]=6;
num[4]=10;
num[5]=15;

for(i=0;i<6;i++)
cout<<setw(4)<<num[i]<<' ';
cout<<endl;
menor=num[0];
for(i=0;i<6;i++)
{if(menor>num[i])
{ menor=num[i];}}
cout<<"\n el menor es: "<<menor<<endl;

mayor=num[0];
for(i=0;i<6;i++)
{if(mayor<num[i])
{ mayor=num[i];}}
cout<<"\n el menor es: "<<mayor<<endl;

pro=0;
for(i=0;i<6;i++)
pro=pro + num[i];
pro=pro*1.0/6;
cout<<"\n el promedio es "<<pro<<endl;
for(i=0;i<6;i++)
if(pro<num[i])
cout<<"\n el valor mayor al promedio es: "<<num[i]<<endl;
cout<<endl;

h=0;
for(i=0;i<6;i++)
{h=0;
{for(j=0;j<6;j++)
if(num[i]>num[j])
h=h+1;}

ord[h]=num[i];

//cout<<"\n "<<h<<" "<<ord[h]<<endl;


}
cout<<"\n los valores ordenados son: "<<endl;
cout<<endl;
for(i=0;i<6;i++)

cout<<setw(4)<<ord[i]<<' ';
cout<<endl;

system("pause");
}

system("pause");
}
*/
#include "stdafx.h"
#include "iostream"
#include "stdlib.h"
#include "math.h"
#include "iomanip"
#include "time.h"

using namespace std;

void main(){

srand((unsigned)time(NULL));

int i,j,m,n,h,u,s,r,fil,col,matriz[100][100],num[70],ord[100];

cout<<"\n ingresar el numero de filas: ";cin>>fil;


cout<<"\n ingresar el numero de columnas: ";cin>>col;

u=fil*col;

for(i=0;i<fil;i++)
{for(j=0;j<col;j++)
{matriz[i][j]=rand()%51;
num[matriz[i][j]]=i*u/fil+j;
cout<<setw(4)<<num[matriz[i][j]]<<' ';
cout<<endl;
}}
// for(i=0;i<=u-1;u++)
cout<<"los valores generados son: "<<endl;
cout<<endl;
for(i=0;i<fil;i++)
{for(j=0;j<col;j++)
{cout<<setw(4)<<matriz[i][j]<<' '; }
cout<<endl;}

for(m=0;m<=20;m++)
{h=0;
for(n=0;n<=20;n++)

{
for(i=0;i<fil;i++)
{for(j=0;j<col;j++)
{if(i*u/fil+j==num[m])
s=matriz[i][j];}}

for(i=0;i<fil;i++)
{for(j=0;j<col;j++)
{if(i*u/fil+j==num[n])
r=matriz[i][j];}}
//cout<<"los valores generados de s , r son: "<<s<<" "<<r<<endl;

//cout<<"los valores generados de s , r son: "<<s<<" "<<r<<endl;

if(s<r)
h=h+1;

/*if(r==s && num[r]<num[s])


h=h+1;
ord[h]=s;*/
}
cout<<"los valores generados de h son: "<<h<<" "<<s<<" "<<r<<endl;
}
/*
for(i=0;i<=u-1;u++)
{cout<<setw(4)<<ord[i]<<' ';
cout<<endl;}
*/

system("pause");
}
// segunda practica.cpp: define el punto de entrada de la aplicación de consola.
//

#include "stdafx.h"
#include "iostream"
#include "stdlib.h"
#include "math.h"
#include "time.h"

using namespace std;

void main()
{srand((unsigned)time(NULL));
int i,j,k,l,m,n,p,q;

for(;;)

{ i=rand()%45+1;
j=rand()%45+1;
k=rand()%45+1;
l=rand()%45+1;
m=rand()%45+1;
n=rand()%45+1;

if(i!=j && i!=k && i!=l && i!=m && i!=n &&
j!=k && j!=l && j!=m && j!=n &&
k!=l && k!=m && k!=n &&
l!=m && l!=n &&
m!=n)
break;}
cout<<"\n El resultado del juego es: "<<i<<" "<<j<<" "<<k<<" "<<l<<" "<<m<<"
"<<n<<endl;
system("pause");
}
// pràctica 2.cpp: define el punto de entrada de la aplicación de consola.

//problema numero 2)

#include "stdafx.h"
#include "iostream"
#include "stdlib.h"
#include "math.h"
#include "time.h"

using namespace std;

void main()
{srand((unsigned)time(NULL));
int i,j,k,l,m,n,p,q,a,b,c,d,e,f,h;

cout<<"\n introducir su primer nùmero: ";cin>>a;


cout<<"\n introducir su segundo nùmero: ";cin>>b;
cout<<"\n introducir su tercer nùmero: ";cin>>c;
cout<<"\n introducir su cuarto nùmero: ";cin>>d;
cout<<"\n introducir su quinto nùmero: ";cin>>e;
cout<<"\n introducir su sexto nùmero: ";cin>>f;

for(;;)

{ i=rand()%45+1;
j=rand()%45+1;
k=rand()%45+1;
l=rand()%45+1;
m=rand()%45+1;
n=rand()%45+1;

if(i!=j && i!=k && i!=l && i!=m && i!=n &&
j!=k && j!=l && j!=m && j!=n &&
k!=l && k!=m && k!=n &&
l!=m && l!=n &&
m!=n)
break;}

cout<<"\n El resultado del juego es: "<<i<<" "<<j<<" "<<k<<" "<<l<<" "<<m<<"
"<<n<<endl;
h=0;
if(a==i || a==j || a==k || a==l || a==m || a==n)
{ h=h+1;
cout<<"\n el primer valor coincide: "<<a<<endl;}

if(b==i || b==j || b==k || b==l || b==m || b==n)


{ h=h+1;
cout<<"\n el segundo valor coincide: "<<b<<endl;}

if(c==i || c==j || c==k || c==l || c==m || c==n)


{ h=h+1;
cout<<"\n el tercer valor coincide: "<<c<<endl;}

if(d==i || d==j || d==k || d==l || d==m || d==n)


{ h=h+1;
cout<<"\n el cuarto valor coincide: "<<d<<endl;}

if(e==i || e==j || e==k || e==l || e==m || e==n)


{ h=h+1;
cout<<"\n el quinto valor coincide: "<<e<<endl;}

if(f==i || f==j || f==k || f==l || f==m || f==n)


{ h=h+1;
cout<<"\n el sexto valor coincide: "<<f<<endl;}

if(h==6)
{cout<<"\n a conseguido: "<<h<<" aciertos"<<endl;
cout<<"usted ha ganado el premio mayor: "<<endl;}

if(h==5)
{cout<<"\n a conseguido: "<<h<<" aciertos"<<endl;
cout<<"usted ha ganado el segundo premio: "<<endl;}

if(h==4)
{cout<<"\n a conseguido: "<<h<<" aciertos"<<endl;
cout<<"usted ha ganado $1000 de premio: "<<endl;}

if(h==3)
{cout<<"\n a conseguido: "<<h<<" aciertos"<<endl;
cout<<"usted puede cambiar su boleto por la siguiente fecha: "<<endl;}

if(h==2 || h==1 || h==0)


{cout<<"\n a conseguido: "<<h<<" aciertos"<<endl;
cout<<"\n gracias por participar: "<<endl;}

system("pause");
}

//problema numero 3)

//segundo problema

#include "stdafx.h"
#include "iostream"
#include "stdlib.h"
#include "math.h"
#include "iomanip"
#include "time.h"
#include "iomanip"
using namespace std;

void main(){

srand((unsigned)time(NULL));

int i,j,m,n,h,u,fil,col,matriz[100][100],ord[100];
cout<<"\n ingresar el n de la matriz cuadrada: ";cin>>fil;

for(i=0;i<fil;i++)
{for(j=0;j<fil;j++)
{u=rand()%1;
matriz[i][j]=rand()%51*powf(-1,i);
}}

// for(i=0;i<=u-1;u++)
cout<<"los valores generados son: "<<endl;
cout<<endl;
for(i=0;i<fil;i++)
{for(j=0;j<fil;j++)
{cout<<setw(4)<<matriz[i][j]<<' '; }
cout<<endl;}
h=0;
m=0;

for(i=0;i<fil;i++)
{
for(j=0;j<fil;j++)
{if(matriz[i][j]<0)
h=h+1;
else
if(matriz[i][j]>0)
m=m+1;}

cout<<"\n la cantidad de valores negativos son: "<<h<<endl;


cout<<"\n la cantidad de valores positivos son: "<<m<<endl;

h=0;
for(i=0;i<fil;i++)
ord[i]=matriz[i][i];
h=i;
cout<<"El vector diagonal es: "<<endl;
cout<<endl;
for(i=0;i<h;i++)
{cout<<setw(4)<<ord[i]<<' ';}
cout<<endl;

h=0;
for(i=0;i<fil;i++)
ord[i]=matriz[i][fil-1-i];
h=i;
cout<<"El vector secundario es: "<<endl;
cout<<endl;
for(i=0;i<h;i++)
{cout<<setw(4)<<ord[i]<<' ';}
cout<<endl;

system("pause");
}

//problema 4)
#include "stdafx.h"
#include "iostream"
#include "stdlib.h"
#include "math.h"
#include "iomanip"
#include "time.h"
#include "iomanip"
using namespace std;

void main(){
char opcion;
srand((unsigned)time(NULL));

int i,j,l,m,n,A[100],B[100],S[100],D[100],Di[100];
float res[100];

cout<<"\n intoducir longitud de los vectores: ";cin>>n;

for(i=0;i<n;i++)
{A[i]=rand()%50;
B[i]=rand()%50;}

cout<<"\n El vector A[ ] es: "<<endl;


cout<<endl;
for(i=0;i<n;i++)
{cout<<setw(4)<<A[i]<<' ';}
cout<<endl;
cout<<endl;
cout<<"\n El vector B[ ] es: "<<endl;
cout<<endl;
for(i=0;i<n;i++)
{cout<<setw(4)<<B[i]<<' ';}
cout<<endl;

for(i=0;i<n;i++)
{S[i]=A[i]+B[i];}

cout<<"\n El vector A[ ] + B[ ] es: "<<endl;


cout<<endl;
for(i=0;i<n;i++)
{cout<<setw(4)<<S[i]<<' ';}
cout<<endl;

for(i=0;i<n;i++)
{D[i]=A[i]-B[i];}

cout<<"\n El vector A[ ] - B[ ] es: "<<endl;


cout<<endl;
for(i=0;i<n;i++)
{cout<<setw(4)<<D[i]<<' ';}
cout<<endl;

for(i=0;i<n;i++)
{Di[i]=A[i]*1.00/B[i];}

cout<<"\n El vector A[ ]/B[ ] es: "<<endl;


cout<<endl;
for(i=0;i<n;i++)
{cout<<setw(4)<<Di[i]<<' ';}
cout<<endl;

for(i=0;i<n;i++)
{res[i]=A[i]%B[i];}

cout<<"\n El vector A[ ]%B[ ] es: "<<endl;


cout<<endl;
for(i=0;i<n;i++)
{cout<<setw(4)<<res[i]<<' ';}
cout<<endl;

system("pause");

Potrebbero piacerti anche