0% found this document useful (0 votes)
26 views4 pages

Ejercicio 1: Console Console Console Convert Console

This document contains examples of coding exercises in C#. The exercises include calculating the harmonic mean, removing duplicate elements from an array, finding the mode of elements in an array, finding the maximum and minimum elements of a 2D array, taking the inverse of a 2D array, and scoring student answers on a multiple choice test stored in a 2D array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views4 pages

Ejercicio 1: Console Console Console Convert Console

This document contains examples of coding exercises in C#. The exercises include calculating the harmonic mean, removing duplicate elements from an array, finding the mode of elements in an array, finding the maximum and minimum elements of a 2D array, taking the inverse of a 2D array, and scoring student answers on a multiple choice test stored in a 2D array.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Ejercicio 1

int n, i;
double m, s = 0;
System.Console.WriteLine("Cálculo de la media armónica");
System.Console.WriteLine("");
System.Console.WriteLine("Ingrese la cantidad de numeros a
calcular");
n = Convert.ToInt32(Console.ReadLine());
double[] v = new double[100];
for (i = 0; i < n; i++)
{
System.Console.WriteLine("n[" + (i + 1) + "]");
v[i] = Convert.ToDouble(Console.ReadLine());
s = s + (1 / v[i]);
}
m = n / s;
System.Console.WriteLine("la media armonica de los numeros es:" +m);
Console.Read();

Ejercicio 7

int[]elemento = new int[50];


int n, i,j,k;
Console.WriteLine();
Console.WriteLine("Ingrese cantidad de números:");
n= Convert.ToInt32(Console.ReadLine());
for(i=0; i < n; i++)
{
System.Console.WriteLine();
System.Console.WriteLine("Elemento" + (i + 1) + ":");
elemento[i] = System.Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine("Presione cualquier tecla para eliminar elemnto
repetido");
Console.ReadKey();
for (i = 0; i < n; i++)
for (j = i + 1; j < n; j++)
if (elemento[i] == elemento[j])
for (k = j; k < n - 1; k++)
elemento[i] = elemento[k + 1];
n=n-1;
j = i;
Console.WriteLine("La lista ahora tiene: " + n +" elementos");
for (i = 0; i < n; i++)
Console.WriteLine("Elemento: "+(i + 1) + " : " + elemento[i]);
Console.ReadKey();
Ejercicio 5

int[] datos = new int[50];


int i, k, n, moda = 0;
Console.WriteLine();
Console.WriteLine(" Ingrese cantidad de datos para el arreglo: ");
n = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < n; i++)
{
Console.WriteLine();
Console.WriteLine(" Ingrese el dato " + (i + 1) + " : ");
datos[i] = Convert.ToInt32(Console.ReadLine());
}
for (i = 0; i < n; i++)
for (k = i + 1; k < n; k++)
if (datos[i] == datos[k])
{
moda = datos[i];
}
Console.WriteLine(" La moda de los elementos almacenados en arreglo
es: " + moda);
Console.Read();

Ejercicio 9

int f, c, i, j,m,n;
int[,] matriz = new int[50, 50];
System.Console.WriteLine("mayor y menor elemento de una matriz");
System.Console.WriteLine("");
System.Console.WriteLine("ingrese el numero de filas de la matriz");
f=Convert.ToInt32(Console.ReadLine());
System.Console.WriteLine("ingrese el numero columnas de la matriz");
c=Convert.ToInt32(Console.ReadLine());
for (i = 0; i < f; i++)
for (j = 0; j < c; j++)
{
System.Console.WriteLine("M[" + (i + 1) + "," + (j + 1) +
"]");
matriz[i, j] = Convert.ToInt32(Console.ReadLine());
}
Console.WriteLine();
for (i = 0; i < f; i++)
{
for (j = 0; j < c; j++)
{
Console.Write(matriz[i, j] + " ");
}
Console.WriteLine();
}
Console.WriteLine();
m=matriz[0, 1];
n=matriz[0, 1];
for (i = 0; i < f; i++)
for (j = 0; j < c; j++)
{
if (matriz[i, j] >= m)
m = matriz[i, j];
if (matriz[i, j] <= n)
n = matriz[i, j];
}
System.Console.WriteLine("el mayor elemento es :"+m);
System.Console.WriteLine("el menor elemento es:"+n);
Console.Read();

Este es el ejercicio 10

Random r = new Random();

Console.Write("Ingrese el Número de Filas: ");


int filas = int.Parse(Console.ReadLine());
Console.Write("Ingrese el Número de Columnas: ");
int columnas = int.Parse(Console.ReadLine());

int[,] matriz = new int[filas, columnas];

int[,] inversa = new int[filas, columnas];

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


for (int j = 0; j < columnas; j++)

matriz[i, j] = Convert.ToInt32(Math.Pow(r.Next(1, 6), 2));

Console.WriteLine(" Matriz Original ");


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("La matriz inversa es ");


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();

Ejercicio 12

int n, i, j, x=0, y=0,s;


string p;
String[,]M = new string [5,6];
int[] v = new int[100];
System.Console.WriteLine("ingrese el numero de alumnos");
n = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < n; i++)
{
for (j = 0; j < 6; j++)
{
System.Console.WriteLine("ingrese la clave de la pregunta:["
+ (j + 1) + "]");
p = Convert.ToString(Console.ReadLine());
System.Console.WriteLine("ingrese la alternativa marcada por
el alumno:[" + (i + 1) + "]" + "pregunta:[" + (j + 1) + "]");
M[i, j] = Convert.ToString(Console.ReadLine());
if ( M[i, j]==p)
x = x + 4;
if ( M[i, j]!=p)
y = y - 1;
}
s = x + y;
v[i] = s;
x = 0;
y = 0;
}
for (i = 0; i < n; i++)
System.Console.WriteLine("nota de alumno[" + (i + 1) + "]=" + v[i]);
Console.Read();

You might also like