





Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Prepara tus exámenes
Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Prepara tus exámenes con los documentos que comparten otros estudiantes como tú en Docsity
Encuentra los documentos específicos para los exámenes de tu universidad
Estudia con lecciones y exámenes resueltos basados en los programas académicos de las mejores universidades
Responde a preguntas de exámenes reales y pon a prueba tu preparación
Consigue puntos base para descargar
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Comunidad
Pide ayuda a la comunidad y resuelve tus dudas de estudio
Ebooks gratuitos
Descarga nuestras guías gratuitas sobre técnicas de estudio, métodos para controlar la ansiedad y consejos para la tesis preparadas por los tutores de Docsity
Ejercicios de Progra para practicar
Tipo: Ejercicios
1 / 9
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!






Ejercicio 1: #include "iostream" #include "conio.h" using namespace std; using namespace System; #define fil 10 #define col 15 void genera_y_muestra_matriz(charmatriz) { Random x; char tipo[4] = { ’R’,’N’,’B’,’E’ }; for (int i = 0; i < fil; i++) { for (int j = 0; j < col; j++) { matriz[i][j] = tipo[x.Next(0, 4)]; cout << matriz[i][j] << ’ ’; } cout << endl; } } void frecuencia_quinua_mayor_menor(char matriz) { int c1 = 0, c2 = 0, c3 = 0, c4 = 0; for (int i = 0; i < fil; i++) { for (int j = 0; j < fil; j++) { if (matriz[i][j] == ’R’)c1++; if (matriz[i][j] == ’N’)c2++; if (matriz[i][j] == ’B’)c3++; if (matriz[i][j] == ’E’)c4++; } } cout << endl; if (c1 >= c2 && c1 >= c3 && c1 >= c4)cout << "La quinua con mayor frecuencia es la Roja" << endl; if (c2 >= c1 && c2 >= c3 && c2 >= c4)cout << "La quinua con mayor frecuencia es la Negra" << endl; if (c3 >= c1 && c3 >= c2 && c3 >= c4)cout << "La quinua con mayor frecuencia es la Blanca" << endl; if (c4 >= c1 && c4 >= c2 && c4 >= c3)cout << "La quinua con mayor frecuencia es la Especial" << endl; cout << endl; if (c1 <= c2 && c1 <= c3 && c1 <= c4)cout << "La quinua con menor frecuencia es la Roja" << endl; if (c2 <= c1 && c2 <= c3 && c2 <= c4)cout << "La quinua con menor frecuencia es la Negra" << endl; if (c3 <= c1 && c3 <= c2 && c3 <= c4)cout << "La quinua con menor frecuencia es la Blanca" << endl; if (c4 <= c1 && c4 <= c2 && c4 <= c3)cout << "La quinua con menor frecuencia es la Especial" << endl; cout << endl; } void quinua_especial(char** matriz) { int cont = 0; for (int i = 0; i < fil - 2; i++) for (int j = 0; j < fil - 2; j++) if (matriz[i][j] == ’B’ && matriz[i][j + 1] == ’R’ && matriz[i][j + 2] == ’B’ && matriz[i + 1][j + 1] == ’E’ && matriz[i + 2][j] == ’N’ && matriz[i + 2][j + 1] == ’R ’ && matriz[i + 2][j + 2] == ’N’) {
cont++; cout << "La posicion de la planta especial es: " << i << ";" << j << endl; } cout << "La cantidad de quinuas especiales es: " << cont;
} void main() { Random f; char** matriz; matriz = new char* [fil]; for (char i = 0; i < fil; i++) matriz[i] = new char[col]; genera_y_muestra_matriz(matriz); frecuencia_quinua_mayor_menor(matriz); quinua_especial(matriz); getch();
Ejercicio del profe: #include "iostream"
#include "conio.h"
using namespace std;
using namespace System;
#define filas 10
#define columnas 15
void generar_mostrar(char** Mat)
{ Random M;
char tipo[4] = { ’R’,’N’,’B’,’E’ };
for (int i = 0; i < filas; i++)
{
for (int j = 0; j < columnas; j++)
{ Mat[i][j] = tipo[M.Next(0, 4)];
cout << Mat[i][j]<<’ ’;
}
for (int i = 0; i < filas - 2; i++)
for (int j = 0; j < columnas - 2; j++)
if (Mat[i][j] == ’B’ && Mat[i][j+1] == ’R’ && Mat[i][j + 2] == ’B’
&& Mat[i+1][j+1] == ’E’
&& Mat[i+2][j] == ’N’&& Mat[i+2][j+1] == ’R’ && Mat[i+2][j+2] == ’N’)
{
cont++;
cout << "la posicion de planta especial es: " << i<<","<< j << endl;
}
cout << "la cantidad de quinuas especiales es: " << cont;
}
void quinua_especial2(char** Mat)
{
int cont = 0;
for (int i = 1; i < filas - 1; i++)
for (int j = 1; j < columnas - 1; j++)
if (Mat[i-1][j-1] == ’B’ && Mat[i-1][j] == ’R’ && Mat[i-1][j + 1] == ’B’
&& Mat[i][j] == ’E’
&& Mat[i+1][j-1] == ’N’ && Mat[i+1][j] == ’R’ && Mat[i+1][j+1] == ’N’)
{
cont++;
cout << "la posicion de planta especial es: " << i << "," << j << endl;
}
cout << "la cantidad de quinuas especiales es: " << cont;
}
void main()
Random f;
char ** Matriz;
Matriz = new char* [filas];
for (int i = 0; i < filas; i++)
Matriz[i] = new char[columnas];
generar_mostrar(Matriz);
frecuencia_quinua_mayor_menor(Matriz);
quinua_especial(Matriz);
getch();
Ejercicio 2: #include "iostream" #include "conio.h" using namespace std; using namespace System; void genera_y_muestra_matriz(intmatriz, int fil, int col) { Random x; for (int i = 0; i < fil; i++) { for (int j = 0; j < col; j++) { matriz[i][j] = x.Next(0, 10); cout << matriz[i][j] << ’ ’; } cout << endl; } } void frecuencia_pares_impares(int matriz, int fil, int col) { int cpar = 0, cimp = 0; for (int i = 0; i < fil; i++) for (int j = 0; j < col; j++) if (matriz[i][j] % 2 == 0)cpar++; else cimp++;
cout << "Cantida de pares: " << cpar << endl; cout << "Cantida de impares: " << cimp << endl; } void ubicacion_valles(int** matriz, int fil, int col) { int cvalle = 0; for (int i = 1; i < fil-1; i++)
for (int i = 0; i < N; i++)
{ for (int j = 0; j < M; j++)
{
Mat[i][j] = dado.Next(0, 10);
cout << Mat[i][j] << ’ ’;
}
cout << endl;
}
}
void frecuencia_pares_impares(int ** Mat,int N, int M)
{
int cpar=0, cimpar=0;
for (int i = 0; i < N; i++)
for (int j = 0; j < M; j++)
if (Mat[i][j] % 2 == 0) cpar++;
else cimpar++;
cout << cpar << " pares " << endl;
cout << cimpar << " impares " << endl;
}
void ubicacion_valles(int ** Mat,int N,int M)
{
int cont = 0;
int posi;
int posj;
for (int i = 1; i < N - 1; i++)
for (int j = 1; j < M -1; j++)
if (Mat[i][j] < Mat[i-1][j -1] &&
Mat[i][j] < Mat[i-1][j] &&
Mat[i][j] < Mat[i-1][j+1] &&
Mat[i][j] < Mat[i][j-1] &&
Mat[i][j] < Mat[i][j+1] &&
Mat[i][j] < Mat[i + 1][j-1] &&
Mat[i][j] < Mat[i + 1][j] &&
Mat[i][j] < Mat[i + 1][j+ 1] )
{
cont++;
cout << "la posicion es: " << i << "," << j << endl;
}
cout << "la cantidad de valles es: " << cont;
}
void main()
{
Random f;
int N, M;
do {
cout << "Ingrese N:";
cin >> N;
} while (N < 3 || N>10);
do {
cout << "Ingrese M:";
cin >> M;
} while (M < 3 || M>10);
int** Matriz;