Vous êtes sur la page 1sur 10

UNIVERSIDAD NACIONAL DE E CAJAMARCA

“Norte de la Universidad Peruana”


Facultad de Ingeniería
Escuela Académico Profesional de Ingeniería de Minas

EJERCICIO N°1

Determine el factorial de un número entero positivo ingresado por teclado.


int a, i, f = 1;
Console.WriteLine("Ingrese número:");
a = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= a; i = i + 1) f = f * i;
System.Console.WriteLine("factorial es:" + f);
Console.ReadLine();

EJERCICIO N°2

Leer un número entero positivo N y reportar solamente sus dígitos pares, e indicar
la suma de estos dígitos.

int n, digito = 0, suma = 0;


System.Console.WriteLine("Ingrese numero:");
n = Convert.ToInt32(Console.ReadLine());
while (n > 0)
{
digito = n % 10; n /= 10;
if (digito % 2 == 0)
{
suma = suma + digito;
}
}
System.Console.WriteLine("Suma: " + suma);
Console.Read();

MINERALOGÍA Ing. MONTOYA TOROVERERO FRANKLIN


UNIVERSIDAD NACIONAL DE E CAJAMARCA
“Norte de la Universidad Peruana”
Facultad de Ingeniería
Escuela Académico Profesional de Ingeniería de Minas

EJERCICIO N°3

Escriba un programa que permita leer la edad (15 a 25) y el sexo (M, F) de n
alumnos y reportar:
a) Cantidad de hombres mayores de edad.
b) Cantidad de mujeres menores de edad.
c) Edad promedio de hombres
d) Edad promedio de mujeres
e) Edad promedio total.
int P, i, e, S = 0, c = 0, d = 0, eh = 0, em = 0, ch = 0, cm = 0;
decimal pH = 0, pM = 0, p = 0;
char s;
System.Console.WriteLine("ingrese cantidad de personas:");
P = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= P; i++)
{
System.Console.WriteLine("persona " + i);
System.Console.WriteLine("edad:");
e = Convert.ToInt32(Console.ReadLine());
S = S + e;
System.Console.WriteLine("sexo:");
s = Convert.ToChar(Console.ReadLine());
if (e >= 15 && e <= 25)
switch (s)
{
case 'H': eh = eh + e; ch = ch + 1;
if (e >= 18) c = c + 1;
break;
case 'M':
em = em + e; cm = cm + 1;
if (e < 18) d = d + 1;
break;
}
}
pH = (eh / ch);
pM = (em / cm);
p = (S / P);
System.Console.WriteLine("edad promedio: " + p);
System.Console.WriteLine("cantidad de HOMBRES mayores de edad:" + c);
System.Console.WriteLine("cantidad de MUJERES menores de edad:" + d);
System.Console.WriteLine("promedio de edad de MUJERES:" + pM);
System.Console.WriteLine("promedio de edad de HOMBRES:" + pH);
Console.ReadLine();

MINERALOGÍA Ing. MONTOYA TOROVERERO FRANKLIN


UNIVERSIDAD NACIONAL DE E CAJAMARCA
“Norte de la Universidad Peruana”
Facultad de Ingeniería
Escuela Académico Profesional de Ingeniería de Minas

EJERCICIO N°4

Escriba un programa que permita ingresar el precio unitario y la cantidad del


producto a comprar, luego debe preguntarle si desea comprar otro producto, si la
respuesta es “S” le pedirá ingresar nuevamente los datos, pero si la respuesta es
“N” mostrará el monto total a pagar.
int M = 0, Pu, Cc;
char O;
System.Console.WriteLine("ingrese precio unitario: ");
Pu = Convert.ToInt32(Console.ReadLine());
System.Console.WriteLine("ingrese cantidad a comprar: ");
Cc = Convert.ToInt32(Console.ReadLine());
M = M + (Pu * Cc);
do
{
System.Console.WriteLine("desea comprar otro producto:");
O = Convert.ToChar(Console.ReadLine());
switch (O)
{
case 'S':
System.Console.WriteLine("ingrese precio unitario: ");
Pu = Convert.ToInt32(Console.ReadLine());
System.Console.WriteLine("ingrese cantidad a comprar: ");
Cc = Convert.ToInt32(Console.ReadLine());
M = M + (Pu * Cc);
break;
case 'N':

MINERALOGÍA Ing. MONTOYA TOROVERERO FRANKLIN


UNIVERSIDAD NACIONAL DE E CAJAMARCA
“Norte de la Universidad Peruana”
Facultad de Ingeniería
Escuela Académico Profesional de Ingeniería de Minas

break;
}
}
while (O != 'N');
System.Console.WriteLine("MONTO A PAGAR: " + M);
Console.ReadLine();

EJERCICIO N°5
Desarrolle un programa para la empresa Constructora Tecnovivir Casas C.A., que
le permita calcular e imprimir la nómina para su cancelación de 10 obreros
calificados a quienes debe cancelar por horas trabajadas. La hora trabajada se
pautó en S/. 12, y la hora extra en S/. 15. Además considerar un descuento por
obrero de AFP del 13 %.

double a, m = 0, i, AFP;
int ht, he;
for (i = 1; i <= 10; i++)
{
System.Console.WriteLine(" Trabajador" + i + ":");
System.Console.Write(" Horas trabajadas:");
ht = Convert.ToInt32(Console.ReadLine());
System.Console.Write(" Horas extra: ");
he = Convert.ToInt32(Console.ReadLine());
a = (12 * ht) + (15 * he);

AFP = ((13 * a) / 100);


m = a - AFP;
System.Console.WriteLine(" El descuento por AFP es:" + AFP);
System.Console.WriteLine(" El monto a cancelar al trabajador es:" +
m);
}
Console.Read();

MINERALOGÍA Ing. MONTOYA TOROVERERO FRANKLIN


UNIVERSIDAD NACIONAL DE E CAJAMARCA
“Norte de la Universidad Peruana”
Facultad de Ingeniería
Escuela Académico Profesional de Ingeniería de Minas

EJERCICIO N° 6

Encuentre el mayor y menor elemento de un array.

int n, mayor = 0, menor = 0;


Console.WriteLine("NUMERO DE ELEMENTOS: ");
n = Convert.ToInt32(Console.ReadLine());
int[] v = new int[n];
for (int i = 0; i < v.Length; i++)
{
Console.WriteLine("elemento" + (i + 1) + ": ");
v[i] = Convert.ToInt32(Console.ReadLine());
}
for (int i = 0; i < v.Length; i++)
{
Console.WriteLine(" " + v[i] + " ");
}
for (int i = 0; i < v.Length; i++)
{
mayor = v[i];
menor = v[i];
for (int j = 0; j < v.Length; j++)
{
if (v[j] > mayor)
mayor = v[j]; if (v[j] < menor) menor = v[j];
}
}
Console.WriteLine();
Console.WriteLine("MAYOR: " + mayor);
Console.WriteLine("MENOR: " + menor);
Console.ReadKey();

MINERALOGÍA Ing. MONTOYA TOROVERERO FRANKLIN


UNIVERSIDAD NACIONAL DE E CAJAMARCA
“Norte de la Universidad Peruana”
Facultad de Ingeniería
Escuela Académico Profesional de Ingeniería de Minas

EJERCICIO N°7

Lea dos arrays A y B y diga que elementos de A no están en B.

int n;
Boolean bandera = false;
Console.WriteLine("Número de elementos: ");
n = Convert.ToInt32(Console.ReadLine());
int[] a = new int[n];
int[] b = new int[n];
for (int i = 0; i < a.Length; i++)
{
Console.WriteLine("Elemento " + (i + 1) + " de a: ");
a[i] = Convert.ToInt32(Console.ReadLine());
}
for (int i = 0; i < a.Length; i++)
{
Console.Write(a[i]);
}
Console.WriteLine();
for (int i = 0; i < b.Length; i++)
{
Console.WriteLine("Elemento" + (i + 1) + "de b: ");
b[i] = Convert.ToInt32(Console.ReadLine());
}
for (int i = 0; i < b.Length; i++)
{
Console.Write(b[i]);
}
Console.WriteLine();
for (int i = 0; i < a.Length; i++)
{
for (int j = 0; j < b.Length; j++)
if (a[i] == b[j]) bandera = true;
if (bandera == false)
Console.Write(a[i] + " no esta en b");

MINERALOGÍA Ing. MONTOYA TOROVERERO FRANKLIN


UNIVERSIDAD NACIONAL DE E CAJAMARCA
“Norte de la Universidad Peruana”
Facultad de Ingeniería
Escuela Académico Profesional de Ingeniería de Minas

bandera = false;
}
Console.Read();

EJERCICIO N°8

Suponga que tiene n elementos en un array ordenado ascendentemente. Inserte


un elemento en la posición que corresponda para mantener el array ordenado.
int n, elemento, a = 0;
Console.WriteLine("Número de elementos: ");
n = Convert.ToInt32(Console.ReadLine());
int[] v = new int[n];
int[] va = new int[n + 1];
for (int i = 0; i < v.Length; i++)
{
Console.WriteLine("v" + (i + 1) + ": ");
v[i] = Convert.ToInt32(Console.ReadLine());
}
for (int i = 0; i < v.Length; i++)
{
Console.WriteLine(v[i] + "|");
}
Console.WriteLine();
Console.WriteLine("elemento: ");
elemento = Convert.ToInt32(Console.ReadLine());
for (int i = 0; i < va.Length; i++)
{
if (elemento > v[i])
{

MINERALOGÍA Ing. MONTOYA TOROVERERO FRANKLIN


UNIVERSIDAD NACIONAL DE E CAJAMARCA
“Norte de la Universidad Peruana”
Facultad de Ingeniería
Escuela Académico Profesional de Ingeniería de Minas

va[i] = elemento;
a++;
break;
}
else
a++;
va[i] = v[i];
}

for (int i = a; i < va.Length; i++)


{
va[i] = v[i - 1];
}

for (int i = 0; i < va.Length; i++)


{
Console.WriteLine(va[i]);
}
Console.Read();

EJERCICIO N°9

La moda de un conjunto de datos es el elemento que más se repite. Encuentre la


moda de elementos almacenados en un array.

int[] num = new int[50];


int i, j, n, m = 0;
Console.Write(" Ingrese cantidad de numeros: ");
n = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= n; i++)
{
Console.WriteLine(" Ingrese el numero " + i + " : ");
num[i] = Convert.ToInt32(Console.ReadLine());

MINERALOGÍA Ing. MONTOYA TOROVERERO FRANKLIN


UNIVERSIDAD NACIONAL DE E CAJAMARCA
“Norte de la Universidad Peruana”
Facultad de Ingeniería
Escuela Académico Profesional de Ingeniería de Minas

}
for (i = 0; i <= n; i++)
for (j = i + 1; j < n; j++)
if (num[i] == num[j])
{
m = num[i];
}
Console.WriteLine(" La moda del arreglo es: " + m);
Console.Read();

EJERCICIO N°10

Calcule la media armónica de un conjunto de datos.


double suma = 0;
System.Console.WriteLine("Ingresar la cantidad de numeros: ");
int cant = Convert.ToInt32(Console.ReadLine());

for (int i = 1; i <= cant; i++)


{
System.Console.WriteLine("Nº" + i + ": ");
int num = Convert.ToInt32(Console.ReadLine());
suma = suma + .1 / num;
}
System.Console.WriteLine("Media Armonica = " + (cant / suma) / 10);
Console.Read();

MINERALOGÍA Ing. MONTOYA TOROVERERO FRANKLIN


UNIVERSIDAD NACIONAL DE E CAJAMARCA
“Norte de la Universidad Peruana”
Facultad de Ingeniería
Escuela Académico Profesional de Ingeniería de Minas

MINERALOGÍA Ing. MONTOYA TOROVERERO FRANKLIN

Vous aimerez peut-être aussi