Problema #1
1) Haga un programa para generar números aleatorios en un arreglo bidimensional 8x8.
a) Función para generar los datos aleatorios en el rango que usted selecciones y almacenarla en un archivo de texto
b) Función para sumar los números pares de la matriz y una suma de los números impares y desplegar cual fue la mayor suma
c) Función para sumar las columnas de la matriz y desplegar que columna tiene la mayor suma
d) Función ara desplegar la matriz
e) Función desplegar los números pares de cada renglón
Pseudocódigo
INICIO
funcion genera_random(int [][8]);
funcion sumar_columnas(int [][8],int);
funcion desplegar_pares(int [][8],int);
funcion sumar_comparar_pares_impares(int [][8],int);
{
int continuar=1;
do {
int num [8][8];
Print FUNCION QUE GENERA LA MATRIX 8x8"
genera_random(num);
Print "---------------------------------------------"
sumar_comparar_pares_impares(num,0);
Print "---------------------------------------------"
sumar_columnas(num,0);
Print "---------------------------------------------" ;
desplegar_pares(num,0);
Print "¿DESEA CREAR OTRA MATRIZ ALEATORIA? SI=1 - NO=2"
Read continuar;
system("cls");
}while (continuar==1);
return 0;
}
void genera_random(int a[][8]){
int rango;
Print "SELECCIONE UN RANGO DE NUMEROS ALEATORIOS: "
Read rango;
Print "MATRIZ GENERADA"
ofstream archivo("MATRIZ.txt");
int i=0;
int j=0;
int num [i][j];
for (i=0 to 08 step i=i+1){
archivo << "\t\t" << endl;
cout << "\t\t" << endl;
for (j=0 to 08 step j=j+1){
a [i][j]= rand()%(rango+1);
cout << "\t" << a [i][j];
archivo << "\t" << a [i][j];
}}
archivo.close();
}
void sumar_columnas(int a[][8],int i){
i=0;
int j=0;
int contador=0;
int colmay=0;
int colmay2=0;
int mayor=0;
int sumcol=0;
for (j=0 to 08 step j=j+1){
sumcol=0;
for (i=0 to 08 step i=i+1){
sumcol+= a[i][j];
}
if (sumcol>mayor){mayor=sumcol; colmay=j+1;}
Print "LA SUMATORIA DE LA COLUMNA ", j+1, " ES: " , sumcol
}
Print "LA COLUMNA CON MAYOR SUMATORIA ES LA COLUMNA ", colmay, " Y SU SUMATORIA ES: ", mayor
}
void desplegar_pares(int a[][8],int i){
int residuo;
i=0;
int j=0;
int sum=0,sum2=0;
for (i=0 to 8 step i=i+1){
Print "\n"
Print "LOS NUMEROS PARES DEL RENGLON ", i+1 , " SON: "
for (j=0 to 08 step j=j+1){
residuo = a [i][j]%2;
if (residuo<1){if (a [i][j] != 0){Print a [i][j], " "}}}}
Print "\n\n";
}
void sumar_comparar_pares_impares(int a[][8],int i){
int sum=0;
int sum2=0;
int residuo;
int j=0;
Print "SUMA DE LOS NUMEROS PARES DE LA MATRIZ COMPARADA CON LA SUMA DE LOS NUMEROS IMPARES"
for (i=0 to 08 step i=i+1){
for (j=0 to 08 step j=j+1){
residuo = a [i][j]%2;
if (residuo==0){sum+=a[i][j];}
else if (residuo>0){sum2+=a[i][j];}
}}
Print "\n", "SUMA DE LOS NUMEROS PARES DE LA MATRIZ: ", sum
Print "SUMA DE LOS NUMEROS IMPARES DE LA MATRIZ: ", sum2
Print "LA SUMA MAYOR FUE: "
if (sum>sum2){Print "LA SUMA DE NUMEROS PARES"}
else if (sum2>sum){Print "LA SUMA DE NUMEROS IMPARES";}}
FIN
CÓDIGO C++:
PROGRAMA EJECUTADO:
ARCHIVO:
Problema #2
Pseudocodigo
INICIO
funcion generaraleatorios(Real [20][4], Real, Real)
funcion calcularpromedio(Real [20][4], Real , Real )
funcion almacenaValores(Real [20][4], Real , Real )
{
Real numero[20][4]
Real const a=20
Real const b=4
generaraleatorios(numero,a, b)
calcularpromedio(numero,a, b)
almacenaValores(numero,a, b )
}
funcion generaraleatorios(Real A[20][4], Real an, Real bn)
{
Real i, j;
srand(time(NULL))
for(i=0 to 20 step i=i+1)
{
for(j=0 to 04 step j=j+1)
{
A[i][j]=rand()%100+1
}
}
}
funcion calcularpromedio(Real A[20][4], Real an, Real bn)
{
Real i, j
Real suma, prom,porcen,porcen1, aprob,reprob
aprob=0
reprob=0
Print "Estudiantes Examen Tareas Practica Proyectos Promedio"
for(i=0 to 20 step i=i+1)
{
suma=0.0
Print " ",i+1
for(j=0 to 04 step j=j+1)
{
Print "\t",A[i][j]
suma=suma+A[i][j]
prom=((suma/4)*0.3)+((suma/4)*0.2)+((suma/4)*0.1)+((suma/4)*0.4)
if(prom>=70)
{
aprob=aprob+1
}
else { if(prom<70)
reprob=20-aprob
}
}
Print" ",prom
}
Print " Los alumnos que aprobaron fueron: ",aprob
porcen=5*aprob
Print " Los alumnos que reprobaron fueron: ",reprob
porcen1=5*reprob
Print " El Porcentaje de alumnos que aprobaron fueron: ",porcen
Print " El Porcentaje de alumnos que reprobaron fueron: ",porcen1
}
funcion almacenaValores(Real A[20][4], Real an, Real bn)
{
Real i, j
ofstream arch1
arch1.open("Escuela.txt")
for(i=0 to 20 step i=i+1)
{
for(j=0 to 04 step j=j+1)
{
arch1<<setw(6)<<A[i][j]
}
arch1
}
arch1.close()
}
FIN
PROGRAMA EJECUTADO:
Problema # 3
Pseudocodigo
INICIO
funcion Leer(Real [30][5])
funcion PorcentajeTipo(Real [30][5])
funcion PromEdad(Real [30][5])
funcion PorcentajeGen(Real [30][5])
funcion PorcentajeEdu(Real [30][5])
funcion info(Real [30][5])
{ Real X[30][5]
Leer(X)
info(X)
PorcentajeTipo(X)
PromEdad(X)
PorcentajeGen(X)
PorcentajeEdu(X) }
Función Leer (Real A[30][5])
{ Real l, z
Real num1,num2,num3,num4
srand(time(NULL))
for(z=0 to 30 step z++)
{
for(l=0 to l step l++){
num1=1+rand()%(3-1)
A[z][l]= num1
}
for(l=1 to 2 step l++){
num2=16+rand() %(77-16)
A[z][l]=num2
}
for(l=2 to 3 step l++){
num3=1+rand() %(3-1)
A[z][l]=num3
}
for(l=3 to 4 stepl++){
num4=1+rand() %(6-1)
A[z][l]=num4
}
}
ofstream archivo1;
archivo1.open("Practica #5.txt");
for(z=0 to 30 step z++)
{
for(l=0 to 4 step l++)
{
archivo1<<A[z][l]
}
archivo1
}
archivo1.close();
}
funcion info(Real A[30][5])
{
Real z,l
Print"Tipo de Licencia Edad Genero Nivel de Escolaridad"
for(z=0 to 30 step++)
{
for(l=0 to 4 step l++)
{
}
}
funcion PorcentajeTipo(Real A[30][5]){
Real z,l
Real X=0.0,Y=0.0,Z
for(z=0 to 30 step z++)
{
for(l=0 to 1 step l++)
{
if (A[z][l]==1)
{
X=X+A[z][l]
lic1=(X*100)/30
}
else
{
Y=Y+A[z][l]
Z=Y/2;
lic2=(Z*100)/30
}
}
}
Print "Porcentaje de licencias Tipo 1: ",lic1
Print "Porcentaje de licencias Tipo 2:",lic2
}
Funcion PromEdad(Real A[30][5])
{
Real z,l,edad
Real Suma=0
for(z=0 to 30 step z++)
{
for(l=1 to 2 step l++)
{
Suma=Suma+A[z][l]
}
edad=Suma/30
}
Print"Promedio de edad: ",edad.
}
funcion PorcentajeGen(Real A[30][5]){
Real z,l
Real Fem, Male,X=0.0,Y=0.0,Z
for(z=0 to 30 step z++)
{
for(l=0 to 1 step l++)
{
if (A[z][l]==1)
{
X=X+A[z][l]
Fem=(X*100)/30
}
else
{
Y=Y+A[z][l]
Z=Y/2
Male=(Z*100)/30
}
}
}
Print "Porcentaje de mujeres: ", Fem
Print "Porcentaje de hombres: ",Male
}
funcion PorcentajeEdu(Real A[30][5]){
Real z,l
Real X=0.0,Y=0.0,Z=0.0,W=0.0
Real w,x,y,p,T,O,R
for(z=0 to 30 step z++)
{
for(l=3 to 4 step l++)
{
if (A[z][l]==1)
{
X=X+A[z][l]
w=(X*100)/30
}
if(A[z][l]==2)
{
Y=Y+A[z][l]
T=Y/2
x=(T*100)/30
}
if(A[z][l]==3)
{
Z=Z+A[z][l]
O=Z/3
y=(O*100)/30
}
else
{
W=W+A[z][l]
R=W/4
p=(R*100)/30
}
}
}
Print"Porcentaje Nivel Educacion"
Print"Educacion Basica: ",w
Print"Educacion Secundaria: ",x
Print"Educacion Preparatoria: ",y
Print"Grado Universitario: ",p
}
FIN
CÓDIGO C++:
PROGRAMA EJECUTADO:
Problema #4
Codigo C++
Pseudocodigo:
Start
//Desplegar
una matriz de 10x10 con números aleatorios que indique cual es la suma menor de
los renglones y el número mayor de los renglones
read
1 función
matriz [10][10],suma,suma2;
2 función
mayor_fila();
3 función menor ();
4 función
diagonal ();
5 función diagonal_invert();
6 función para crear archivo F1.open
7 utiliza el tiempo del ordenador para los números
aleatorios
srand
(time(NULL));
8 cuenta los números que hay del 1 al 10 for(int
i=0;i<10;i++)
9 genera la matriz con los valores aleatorios for
(int a=0;a<10;a++)
10 da un
numero aleatorio matriz[i][a]=rand()% 11;
11
despliega la matriz: matriz[i][a]
12
almacena un valor máximo dentro de x matriz[i][a]
13 permite
almacenar en una siguiente función como un valor global
int
max=0;
14 permite
igualar max a cero para que pueda
inicializarse en cero for(int i = 0; i<10; i++)
15
permite visualizar cual es el menor de cada fila int menor=data[0],i;
for ( i=1;i<10;i++)
{
if(data[i]<menor)
{
menor=data[i];
}
16 read "\nEl
menor es: "
17
permite realizar la suma en diagonal principal suma=suma+matriz[i][i]
18
permite realizar suma en diagonal invertida int a=9;
for (int i=0;i<10;i++)
{
suma2=suma2+matriz[i][a];
a--;
}
19 print "Suma
diagonal invertida: "
End




Programa ejecutado: