Sie sind auf Seite 1von 16

SOLUCIN DE EJERCICIOS

5. La moda de un conjunto de datos es el elemento que ms se repite. Encuentre la moda de


elementos almacenados en un arreglo.
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace EJERCICIO 5 ARREGLOS


{
class Program
{
static void Main(string[] args)
{
int[] elementos = new int[50];
int n, i, j, moda = 0;
Console.WriteLine("Ingrese el Numero de Elementos de un Array");
n = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < n; i++)
{
Console.WriteLine("Ingrese el Elemento " + (i + 1) + " :");
elementos[i] = Convert.ToInt32(Console.ReadLine());
}
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if (elementos[i] == elementos[j])
{
moda = elementos[i];
}

}
}

Console.WriteLine("La Moda es: " + moda);


Console.Read();

6. Realizar la bsqueda de un determinado elemento dentro de un arreglo, indicando su


posicin en el vector, de caso contrario se mostrar un mensaje Elemento no encontrado.
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace ejercicio_6_arreglos
{
class Program
{
static void Main(string[] args)
{
int[] numero = new int[50];
int n, nb, i, pos = 0, verificador = 0;
System.Console.WriteLine();
System.Console.WriteLine("Ingrese cantidad de numeros:");
n = System.Convert.ToInt32(Console.ReadLine());
for (i = 0; i < n; i++)
{
System.Console.WriteLine();
System.Console.WriteLine("Numero" + (i + 1) + ":");
numero[i] = System.Convert.ToInt32(Console.ReadLine());
}
System.Console.WriteLine();
System.Console.WriteLine("Ingrese numero a buscar:");
nb = System.Convert.ToInt32(Console.ReadLine());
for (i = 0; i < n; i++)
{
if (nb == numero[i])
{
pos = i;
verificador = 1;
}
}
if (verificador == 1)
{
System.Console.WriteLine();
System.Console.WriteLine("El numero esta en la posicion = " + (pos + 1));
}
else
{
System.Console.WriteLine();
System.Console.WriteLine("ELEMENTO NO ENCONTRADO");
}
Console.ReadKey();
}
}
}

7. Elimine los elementos repetidos de un arreglo.


using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace EJERCICIO_7_ARREGLOS
{
class Program
{
static void Main(string[] args)
{
int[] lista = new int[50];
int i, j, k, n;
Console.Write("Ingrese cantidad de elementos de la lista:");
n = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < n; i++)
{
Console.Write("Elemento " + (i + 1) + ":");
lista[i] = Convert.ToInt32(Console.ReadLine());
}
Console.Write("Presione cualquier tecla para eliminar elementos repetidos");
Console.ReadKey();
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if (lista[i] == lista[j])
{
for (k = j; k < n - 1; k++)
lista[k] = lista[k + 1];
n = n - 1;
j = i + 1;
}
Console.WriteLine();
Console.WriteLine("La nueva tiene: " + n + " elementos");
for (i = 0; i < n; i++)
Console.WriteLine("Elemento " + (i + 1) + ":" + lista[i]);
Console.Read();
Console.Write("Presione cualquier tecla para buscar elementos repetidos");
Console.ReadKey();
}

8. Ordene un conjunto de datos de menor a mayor por cualquiera de los mtodos presentados

using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace ConsoleApplication51
{
class Program
{
static void Main(string[] args)
{
double[] numero = new double[50];
double cambio = 0;
int i, j, n;
Console.WriteLine("Ingrese el Numero de Datos: ");
n = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < n; i++)
{
Console.Write("El numero " + (i + 1) + " es: " + " ");
numero[i] = Convert.ToInt32(Console.ReadLine());
}
for (i = 1; i < n; i++)
for (j = n - 1; j >= i; j--)
if (numero[j - 1] > numero[j])
{
cambio = numero[j - 1];
numero[j - 1] = numero[j];
numero[j] = cambio;
}
Console.WriteLine("Los Numeros ordenados de Menor a Mayor son: ");
for (i = 0; i < n; i++)
{
Console.WriteLine("Numero " + (i + 1) + " es:" + numero[i] + " ");
}
Console.Read();
}

9. Escribir un programa que lea una matriz, y a continuacin encuentre el mayor y el menor
elemento de la matriz y sus posiciones.

using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Pregunta_N_1
{
class Program
{
public static void leerMatriz(int[,] matriz, int f, int c)
{
int i, j;
for (i = 0; i < f; i++)
for (j = 0; j < c; j++)
{
Console.Write("Matriz[{0},{1}]: ", i, j);
matriz[i, j] = Convert.ToInt32(Console.ReadLine());
}
}
public static void escribirMatriz(int[,] matriz1, int f, int c)
{
int i, j = 0;
for (i = 0; i < f; i++)
{
for (j = 0; j < c; j++)
Console.Write("Matriz[{0},{1}]: ", i, j, matriz1[i, j]);
Console.WriteLine();
}
}
static void Main(string[] args)
{
int[,] matriz1 = new int[10, 10];
int i, j, c1, f1, mayor = 0, menor = 100000, filamay = 0, colummay = 0, filamen
= 0, colummen = 0;
Console.WriteLine("Nro de filas y columnas de la matriz :");
f1 = Convert.ToInt32(Console.ReadLine());
c1 = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("La Matriz es: ");
leerMatriz(matriz1, c1, f1);
for (i = 0; i < c1; i++)
{
for (j = 0; j < f1; j++)
{
if (matriz1[i, j] > mayor)
{
mayor = matriz1[i, j];
filamay = i;
colummay = j;
}
}
}
for (i = 0; i < c1; i++)
{
for (j = 0; j < f1; j++)
{

if (matriz1[i, j] < menor)


{
menor = matriz1[i, j];
filamen = i;
colummen = j;
}

}
Console.WriteLine("El Numero Mayor es: " + mayor);
Console.WriteLine("La Posicion de Numero Mayor es: " + filamay + "," +
colummay);
Console.WriteLine("El Numero Menor es: " + menor);
Console.WriteLine("La Posicion de Numero Menor es: " + filamen + "," +
colummen);
}
}

Console.Read();

10. Elaborar un programa que calcule la matriz inversa, de una matriz dada, cuyas dimensiones
son ingresadas por teclado.

using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace ConsoleApplication42
{
class Program
{
static void Main(string[] args)
{
Random r = new Random();
Console.Write("Ingrese el Nmero de Filas: ");
int filas = int.Parse(Console.ReadLine());
Console.Write("Ingrese el Nmero de Columnas: ");
int columnas = int.Parse(Console.ReadLine());
int[,] matriz = new int[filas, columnas];
int[,] inversa = new int[filas, columnas];
Console.WriteLine("");
for (int i = 0; i < filas; i++)
for (int j = 0; j < columnas; j++)
{
Console.Write(" matriz N [{0},{1}]): ", i, j);
matriz[i, j] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("");
// MOSTRAR LA MATRIZ NORMAL
Console.WriteLine(" MATRIZ NORMAL: ");
for (int i = 0; i < filas; i++)
{
for (int j = 0; j < columnas; j++)
Console.Write(string.Format("{0,4:D}", matriz[i, j]));
Console.WriteLine();
}
Console.WriteLine("");
//imprimiendo inversa de matriz
Console.WriteLine("\n * La matriz inversa es *\n");
for (int i = 0; i < filas; i++)
{
for (int j = 0; j < columnas; j++)
{
inversa[i, j] = matriz[filas - i - 1, columnas - j - 1];
Console.Write(string.Format("{0,4:D}", inversa[i, j]));
}
Console.WriteLine();
}
Console.ReadKey();
}
}

11. El dueo de un restaurante entrevista a cinco clientes de su negocio y les pide que
califiquen del 1 a 10 los siguientes aspectos: (1 es psimo y 10 es excelente)
a. Atencin de los empleados
b. Calidad de la comida
c. Justicia del precio
d. Ambiente
Elabore un programa que pida las calificaciones de N clientes en cada uno de los aspectos
mencionados, y luego escriba el promedio obtenido en cada uno de ellos. La lista debe
aparecer ordenada del aspecto mejor calificado al peor calificado.
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Pregunta_N_4
{
class Program
{
static void Main(string[] args)
{
int cli;
Console.Write("N de clientes: ");
cli = Convert.ToInt32(Console.ReadLine());
int[,] ma = new int[cli, 4];
for (int i = 0; i < cli; i++)
{
Console.Write("Calificacin de cliente " + (i + 1) + ": \n");
do
{

Console.Write("Atencin de los empleados: ");


ma[i, 0] = Convert.ToInt32(Console.ReadLine());
} while (ma[i, 0] < 1 || ma[i, 0] > 10);

do
{

Console.Write("Calidad de comida: ");


ma[i, 1] = Convert.ToInt32(Console.ReadLine());
} while (ma[i, 0] < 1 || ma[i, 0] > 10);

do
{

Console.Write("Justicia de precio: ");


ma[i, 2] = Convert.ToInt32(Console.ReadLine());
} while (ma[i, 0] < 1 || ma[i, 0] > 10);

do
{

Console.Write("Ambiente: ");
ma[i, 3] = Convert.ToInt32(Console.ReadLine());
} while (ma[i, 0] < 1 || ma[i, 0] > 10);

}
int[] prome = new int[4];
int[] nca = new int[4] { 0, 1, 2, 3 };

for (int i = 0; i < cli; i++)


{
prome[0] = prome[0] +
prome[1] = prome[1] +
prome[2] = prome[2] +
prome[3] = prome[3] +

ma[i,
ma[i,
ma[i,
ma[i,

0];
1];
2];
3];

}
for (int i = 0; i < 4; i++) { prome[i] = prome[i] / cli; }
for (int i = 0; i < 4; i++)
{
for (int j = i + 1; j < 4; j++)
{
if (prome[i] < prome[j])
{
int a, b;
a = prome[i];
prome[i] = prome[j];
prome[j] = a;
b = nca[i];
nca[i] = nca[j];
nca[j] = b;
}

}
Console.Write("\nCALIFICACIONES: \n");
for (int i = 0; i < 4; i++)
{
switch (nca[i])
{
case 0:
Console.Write("Atencin de los empleados: ");
break;
case 1:
Console.Write("Calidad de comida: ");
break;
case 2:
Console.Write("Justicia de precio: ");
break;
case 3:
Console.Write("Ambiente: ");
break;
}
Console.Write(prome[i] + "\n");
}
Console.Read();
}
}

12. Construir un programa que califique un examen de seleccin presentado


por n estudiantes de Programacin de Computadores. El examen consta de
6 preguntas con 5 alternativas: A, B, C, D y E. Mostrar los resultados del
examen por alumno. (preg. correcta = 4 ptos, preg. incorrecta= -1)
using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace ConsoleApplication49
{
class Program
{
static void Main(string[] args)
{
char[] respuestas = new char[6];
char[] clavesporestudiante = new char[6];
char[] estudiante = new char[50];
int n, i, j, nota = 0, respuestascorrectas = 0, respuestasincorrectas = 0;
Console.WriteLine("Ingrese el Numero de Estudiantes");
n = Convert.ToInt32(Console.ReadLine());
respuestas[0]
respuestas[1]
respuestas[2]
respuestas[3]
respuestas[4]
respuestas[5]

=
=
=
=
=
=

'A';
'B';
'E';
'C';
'D';
'D';

for (j = 0; j < n; j++)


{
{
Console.WriteLine("Estudiante " + (j + 1) + " :");
Console.WriteLine("Ingrese las Respuestas del Estudiante " + (j + 1) + " :");
}
for (i = 0; i < 6; i++)
{
Console.Write(" Respuesta del Estudiante " + (j + 1) + " de la Pregunta N "
+ (i + 1) + " : ");
clavesporestudiante[i] = Convert.ToChar(Console.ReadLine());
}
for (i = 0; i < 6; i++)
{
if (clavesporestudiante[i] == respuestas[i])
respuestascorrectas = respuestascorrectas + 1;
if (clavesporestudiante[i] != respuestas[i])
respuestasincorrectas = respuestasincorrectas + 1;
}
nota = 4 * respuestascorrectas - respuestasincorrectas;
Console.WriteLine("Las Respuestas Correctas para el Alumno " + (j + 1) + "
es:" + respuestascorrectas);
Console.WriteLine("Las Respuestas Incorrectas para el Alumno " + (j + 1) + "
es:" + respuestasincorrectas);
Console.WriteLine("La nota del alumno " + (j + 1) + " es: " + nota);
respuestascorrectas = 0;
respuestasincorrectas = 0;

}
}

}
Console.Read();

13. Los resultados de las ltimas elecciones a alcalde en una provincia X han sido las
siguientes:
Distrito\Candi
dato
Distrito 1
Distrito 2
Distrito 3
Distrito 4
Distrito 5

using
using
using
using

Candidato A

Candidato B

Candidato C

Candidato D

114
79
32
194
164

157
196
23
80
172

133
49
164
124
181

164
174
181
45
125

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Pregunta_N__1
{
class Program
{
static void Main(string[] args)
{
string[,] matriz1 = new string [10, 10];
int i, j, A, B, C, D;
//Ingreso de la Matriz
Console.WriteLine("En las posicion (0,0) ingrese: Distrito/Candidato");
Console.WriteLine("En las posicion (1,0), (2,0), (3,0), (4,0), (5,0) ingrese los 5
distritos");
Console.WriteLine("En las otras posiciones ingrese los resutados");
for (i = 0; i < 6; i++)
for (j = 0; j < 5; j++)
{
Console.Write("Matriz 1 [{0}, {1}] : ", i, j);
matriz1[i, j] = Convert.ToString(Console.ReadLine()); ;
}
//Motramos Matriz
Console.WriteLine("La Matriz es: ");
for (i = 0; i < 6; i++)
{
for (j = 0; j < 5; j++)
Console.Write("
" + matriz1[i, j] + " ");
Console.WriteLine();
}

// Total de Votos
A = 118 + 153 + 164 + 128 + 183;
B = 190 + 122 + 148 + 68+142;
C = 76 + 167 + 92 + 157 + 158;
D = 143 + 197 + 96 + 71 + 119;
Console.WriteLine("El Total de Votos para el Candidato A es de: " + A);
Console.WriteLine("El Total de Votos para el Candidato B es de: " + B);
Console.WriteLine("El Total de Votos para el Candidato C es de: " + C);
Console.WriteLine("El Total de Votos para el Candidato D es de: " + D);
Console.WriteLine();
Console.WriteLine("El Candidato mas Votado es el Canditado A con " + A + "
Votos");

Console.Read();
}

15. Desarrolle un programa aplicado a la minera, utilizando arreglos.


using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace ConsoleApplication52
{
class Program
{
static void Main(string[] args)
{
int[] testigos = new int[50];
int[] diametro = new int[50];
int[] cargaultima = new int[50];
double[] resistencia = new double[50];
int n, i, ban = 0;
double menor;
Console.WriteLine("Ingrese la Cantidad de Testigos a analizar: ");
n = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Ingrese un Numero o nombre para Cada Testigo: ");
for (i = 0; i < n; i++)
{
Console.Write("Testigo: ");
testigos[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Ingrese Diametro para Testigo " + testigos[i] + " :");
diametro[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Ingrese la Carga Ultima para Testigo " + testigos[i] + " :");
cargaultima[i] = Convert.ToInt32(Console.ReadLine());
}
for (i = 0; i < n; i++)
{
resistencia[i] = (4 * cargaultima[i]) / (3.14 * diametro[i] * diametro[i]);
Console.WriteLine("La Resistencia a Compresion Uniaxial para el Testigo " +
testigos[i] + " es: " + resistencia[i]);
}
menor = resistencia[0];

for (i = 1; i < n; i++)


{
if (resistencia[i] < menor)
{
menor = resistencia[i];
Console.WriteLine("La Resistencia Menor es: " + resistencia[i] + "y decimos
que este testigo es muy debil");
ban = 1;
}
if (ban == 0)
Console.WriteLine("La Resistencia Mayor es: " + resistencia[i] + "y decimos
que este testigo es muy competente o resistente");
}
Console.Read();

using
using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;
System.Threading.Tasks;

namespace Ejercicio_N__12/*Desarrolle un programa aplicado a la minera, utilizando


arreglos.
Enunciado:UNA EMPRESA MINERA DESEA CONOCER EL TIPO DE
SOSTENIMIENTO QUE NECESITAR
SU PROYECTO. PARA LO CUAL, SE BASAN EN EL RESULTADO DE LOS
RQD ENCONTRADOS EN LAS
PRUEBAS DE CAMPO. DISEAR UN PROGRAMA QUE ENCUENTRE EL
RQD DE LAS CUATRO ESTACIONES,
HALLE EL PROMEDIO Y NOS ARROJE EL METODO DE SOSTENMIENTO A
USAR:

VALOR PROMEDIO DEL RQD


0-25
26-50
51-75
76-100

TIPO DE SOSTENIMIENTO

CUADROS DE MADERA
CONCRETO LANZADO
PERNOS DE ANCLAJE
SIN SOSTENIMIENTO

*/

class Program
{
static void Main(string[] args)
{
int[] ESTACIONES = new int[50];
int[] LONGITUD_TRAMO = new int[50];
int[] NUMERO_DISCONTINUIDADES = new int[50];
int i, n;
double y, RQD, suma_RQD = 0, promedio_RQD;
Console.WriteLine();
Console.WriteLine("INGRESE NUMERO DE ESTACIONES A ANALIZAR:");
n = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < n; i++)
{
Console.WriteLine("Estacin N:");
ESTACIONES[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Console.WriteLine("Ingrese longitud(m) del tramo :");
LONGITUD_TRAMO[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
Console.WriteLine("Ingrese nmero de discontinuidades del tramo:");
NUMERO_DISCONTINUIDADES[i] = Convert.ToInt32(Console.ReadLine());
Console.WriteLine();
}
Console.Write("Presione cualquier tecla para calcular RQD de cada estacin ");
Console.ReadKey();
for (i = 0; i < n; i++)
{
y = NUMERO_DISCONTINUIDADES[i] / LONGITUD_TRAMO[i];
RQD = 100 * Math.Exp(-0.1 * y * (0.1 * y + 1));
Console.WriteLine("El RQD calculado, basndonos en los parmetros
ingresados de la Estacin N: " + (i + 1) + " es: " + RQD);
Console.WriteLine();
suma_RQD = suma_RQD + RQD;
}
promedio_RQD = suma_RQD / n;
Console.WriteLine();
Console.WriteLine("El promedio del RQD calculado es: " + promedio_RQD);
if (promedio_RQD < 26)
{
Console.WriteLine();
Console.WriteLine("EL TIPO DE SOSTENIMIENTO A UTILIZAR ES: CUADROS DE
MADERA ");
}
if (promedio_RQD > 25 && promedio_RQD < 51)
{
Console.WriteLine();
Console.WriteLine("EL TIPO DE SOSTENIMIENTO A UTILIZAR ES: CONCRETO
LANZADO ");
}
if (promedio_RQD > 50 && promedio_RQD < 76)
{

Console.WriteLine();
Console.WriteLine("EL TIPO DE SOSTENIMIENTO A UTILIZAR ES: PERNOS DE
ANCLAJE ");
}
if (promedio_RQD > 75)
{
Console.WriteLine();
Console.WriteLine("NO SE REQUIERE SOSTENIMIENTO");
}
Console.ReadKey();
}
}
}

using
using
using
using

System;
System.Collections.Generic;
System.Linq;
System.Text;

namespace Ejercicion_N__7
{
class Program
{
static void Main(string[] args)
{
int[] elementosA = new int[50];
int[] elementosB = new int[50];
int[] resultado = new int[50];
int n,n1, i, j, ban=0;
Console.WriteLine("Ingrese Numero de Elemntos de A: ");
n = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < n; i++)
{
Console.WriteLine("Elemento " + (i + 1) + " de A es: ");
elementosA[i] = Convert.ToInt32(Console.ReadLine());
}

Console.WriteLine("Ingrese Numero de Elemntos de B: ");


n1 = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < n1; i++)
{
Console.WriteLine("Elemento " + (i + 1) + " de B es: ");
elementosB[i] = Convert.ToInt32(Console.ReadLine());
}
for(i=0;i<n;i++)
{
for (j = 0; j < n1; j++)
if ((elementosA[i] == elementosB[j]))
ban = 1;
if (ban == 0)
Console.WriteLine("El elemento: " + elementosA[i] + " no estan en B");
ban = 0;
}
Console.Read();

Das könnte Ihnen auch gefallen