Académique Documents
Professionnel Documents
Culture Documents
Facultad de ingeniera
Escuela acadmico profesional de ingeniera de Minas
CODIGO
namespace ejercicio_1
{
class Program
{
static void Main(string[] args)
{
int n, i,fact=1;
Console.WriteLine("ingrese numero ");
n = Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= n; i++)
fact = fact * i;
Console.WriteLine("el factorial es: " + fact);
Console.Read();
}
CONPUTACION Y ALGORITMOS II
CODIGO
namespace ejercicio_2
{
class Program
{
static void Main(string[] args)
{
int n, d, sd=0,cd=0;
Console.WriteLine("ingrese un numero");
n = Convert.ToInt32(Console.ReadLine());
while (n > 0)
{
d = n % 10;
n = n / 10;
if (d % 2 == 0)
{
cd = cd + 1;
sd = sd + d;
}
}
}
}
Console.WriteLine("la cantidad de digitos pares es: " + cd);
Console.WriteLine("la suma de los digitos pares es: " + sd);
Console.Read();
CONPUTACION Y ALGORITMOS II
CODIGO
namespace ejercicio_3
{
class Program
{
static void Main(string[] args)
{
int p,i,e,sum=0,ehom=0,emuj=0,chom=0,cmuj=0,ma=0,me=0;
double ph, pm, prom;
char g;
Console.WriteLine("ingrese numero de personas: ");
p= Convert.ToInt32(Console.ReadLine());
for (i = 1; i <= p; i++)
{
Console.WriteLine(" ");
CONPUTACION Y ALGORITMOS II
ph = (ehom / chom);
pm = (emuj / cmuj);
prom= (sum / p);
System.Console.WriteLine("cantidad de hombres mayores de edad:" + ma);
System.Console.WriteLine("cantidad de mujeres menores de edad:" + me);
System.Console.WriteLine("promedio de edad de mujeres:" + pm);
System.Console.WriteLine("promedio de edad de hombres:" + ph);
System.Console.WriteLine("edad promedio: " + prom);
Console.ReadLine();
}
CONPUTACION Y ALGORITMOS II
CONPUTACION Y ALGORITMOS II
CODIGO
namespace ejercicio_4
{
class Program
{
static void Main(string[] args)
{
int mon, p, c, cmon = 0, n = 1;
char o;
Console.WriteLine("ingrese precio: ");
p = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("ingrese cantidad: ");
c = Convert.ToInt32(Console.ReadLine());
mon = p * c;
do
{
Console.WriteLine("DESEA HACER OTRA OPERACION: ");
o = Convert.ToChar(Console.ReadLine());
switch (o)
{
case 's':
Console.WriteLine("ingrese precio: ");
CONPUTACION Y ALGORITMOS II
p = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("ingrese cantidad: ");
c = Convert.ToInt32(Console.ReadLine());
cmon = cmon + mon;
mon = p * c;
break;
case 'n':
mon = p * c;
cmon = cmon + mon;
Console.WriteLine("el monto total a pagar es: " + cmon);
n = Convert.ToInt32(Console.ReadLine());
break;
}
} while (o != n);
Console.Read();
}
CODIGO
namespace ejercicio_5
{
class Program
{
CONPUTACION Y ALGORITMOS II
EJERCICIOS DE ARRAYS
CONPUTACION Y ALGORITMOS II
CODIGO
namespace arrays_1
{
class Program
{
static void Main(string[] args)
{
int[] elemento = new int[50];
int n,menor=0,mayor=0, i=0;
Console.Write(" Ingrese cantidad de elementos: ");
n = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < n; i++)
{
Console.Write("elemento" + (i + 1) + ": ");
elemento[i] = Convert.ToInt32(Console.ReadLine());
if (i == 0)
{
mayor = elemento[i];
menor = elemento[i];
}
else
if (i != 0)
{
if (elemento[i] < menor)
{
menor = elemento[i];
}
if (elemento[i] > mayor)
{
mayor = elemento[i];
}
}
}
Console.WriteLine("el mayor numero es:" + mayor);
Console.WriteLine("el menor numero es:" + menor);
Console.Read();
}
}
CONPUTACION Y ALGORITMOS II
CODIGO
namespace ejercicio_7
{
class Program
{
static void Main(string[] args)
{
int n;
Boolean bandera = false;
Console.WriteLine("Nmero de elementos que tendran los grupos: ");
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) + " del arreglo A: ");
a[i] = Convert.ToInt32(Console.ReadLine());
}
for (int i = 0; i < a.Length; i++)
{ Console.WriteLine(a[i] + ">>>"); }
Console.WriteLine();
for (int i = 0; i < b.Length; i++)
{
Console.WriteLine("Elemento" + (i + 1) + "del arreglo B: ");
b[i] = Convert.ToInt32(Console.ReadLine());
}
for (int i = 0; i < b.Length; i++)
{ Console.WriteLine(b[i] + ">>>"); }
Console.WriteLine();
for (int i = 0; i < a.Length; i++)
{
CONPUTACION Y ALGORITMOS II
10
}
Console.ReadKey();
}
CODIGO
namespace ejercicio_9
{
class Program
{
static void Main(string[] args)
{
int[] elementos = new int[50];
int n, i, j, moda = 0;
Console.WriteLine("Ingrese cantidad de numeros: ");
n = Convert.ToInt32(Console.ReadLine());
CONPUTACION Y ALGORITMOS II
11
CONPUTACION Y ALGORITMOS II
12
CODIGO
namespace ejercicio_10
{
class Program
{
static void Main(string[] args)
{
double[] datos = new double[50];
int n, i;
double suma = 0, marmo;
Console.Write(" Ingrese cantidad de datos: ");
n = Convert.ToInt32(Console.ReadLine());
for (i = 0; i < n; i++)
{
Console.Write("dato" + (i + 1) + ": ");
datos[i] = Convert.ToInt32(Console.ReadLine());
}
for (i = 0; i < n; i++)
{
suma = suma + 1/datos[i];
}
marmo = n/suma;
Console.WriteLine("media Armonica: " + marmo);
Console.Read();
CONPUTACION Y ALGORITMOS II
13
CODIGO
namespace ejercicio_11
{
class Program
{
static void Main(string[] args)
{
double[] numero = new double[50];
double intercambio = 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])
{
intercambio = numero[j - 1];
numero[j - 1] = numero[j];
numero[j] = intercambio;
}
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();
}
}
CONPUTACION Y ALGORITMOS II
14
CONPUTACION Y ALGORITMOS II
15
}
Console.WriteLine("el mayor tonelaje es:" + mayor);
Console.WriteLine("el menor nonelaje es:" + menor);
Console.Read();
CONPUTACION Y ALGORITMOS II
16
CONPUTACION Y ALGORITMOS II
17