Ejercicios c#

44
C# Inicialización 1. Bienvenido Nº1 using System; class bienvenido { static void Main(string[] args) { Console.WriteLine("Bienbenido al programa de C# !"); Console.ReadLine(); } } 2. Bienvenido Nº2 using System; class bienvenido2 { static void Main(string[] args) { Console.Write("Bienvenido al "); Console.WriteLine("Programa C# !"); Console.ReadLine(); } } 3. Bienvenido Nº3 using System; class Bienvenido3 { static void Main(string[] args) { Console.WriteLine("Bienvenido\nal\nPrograma\ndeC#!"); Console.ReadLine(); } }

description

programacion inicializando c#

Transcript of Ejercicios c#

Page 1: Ejercicios c#

C# Inicialización 1. Bienvenido Nº1

using System;

class bienvenido

{

static void Main(string[] args)

{

Console.WriteLine("Bienbenido al programa de C# !");

Console.ReadLine();

}

}

2. Bienvenido Nº2

using System;

class bienvenido2

{

static void Main(string[] args)

{

Console.Write("Bienvenido al ");

Console.WriteLine("Programa C# !");

Console.ReadLine();

}

}

3. Bienvenido Nº3

using System;

class Bienvenido3

{

static void Main(string[] args)

{

Console.WriteLine("Bienvenido\nal\nPrograma\ndeC#!");

Console.ReadLine();

}

}

Page 2: Ejercicios c#

4. Digitar un texto de 4 cifras y que luego te muestre de forma horizontal la frase.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

string cadena;

Console.Write("Texto de 4 cifras :");

cadena = Console.ReadLine();

Console.WriteLine(cadena[0]);

Console.WriteLine(cadena[1]);

Console.WriteLine(cadena[2]);

Console.WriteLine(cadena[3]);

Console.ReadLine();

}

}

}

5. Digite una comunicacion escrita con cadenas

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

Console.Write("Hola ");

Console.WriteLine(" Erick");

Console.Write("¿Cómo andas,");

Console.WriteLine("tío?");

Console.ReadLine();

}

}

}

Page 3: Ejercicios c#

6. Creación de contraseñas

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

string clave = "erick";

string res = "";

while (res != clave)

{

Console.Write("Ingrese la clave:");

res = Console.ReadLine();

}

Console.WriteLine("La clave es correcta");

Console.ReadLine();

}

}

}

Page 4: Ejercicios c#

AAApppllliiicccaaaccciiióóónnn “““BBBAAASSSIIICCCAAA”””

1. Hallar la suma de 2 dígitos

using System;

class Addition

{

static void Main(string[] args)

{

int n1, n2, sum;

Console.Write("Primer Numero : ");

n1 = int.Parse (Console.ReadLine());

Console.Write("Segundo Numero: ");

n2 = int.Parse(Console.ReadLine());

sum = n1 + n2;

Console.WriteLine("la suma es : {0}", sum);

Console.ReadLine();

}

}

2. La compra de un producto halla el importe, IGV y sacar el total.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

string nombre;

double precio, cantidad, imp, igv, total;

Console.Write("nombre del producto :");

nombre = (Console.ReadLine());

Console.Write("precio :");

precio = double.Parse(Console.ReadLine());

Console.Write("cantidad :");

cantidad = double.Parse(Console.ReadLine());

imp = precio * cantidad;

igv = (19 / 100.0) * imp;

total = imp + igv;

Console.WriteLine("importe :{0}", imp);

Console.WriteLine("igv : {0}", igv);

Console.WriteLine("total : {0}", total);

Console.ReadLine();

}

}

}

Page 5: Ejercicios c#

3. Hallar el promedio final de un alumno sacando con tres notas de sus estudios.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

string alumno;

double n1, n2, n3, p;

Console.Write("Alumno :");

alumno = (Console.ReadLine());

Console.Write("Nota 1 :");

n1 = double.Parse (Console.ReadLine());

Console.Write("Nota 2 :");

n2 = double.Parse (Console.ReadLine());

Console.Write("Nota 3 :");

n3 = double.Parse(Console.ReadLine());

p = (n1 + n2 + n3) / 3;

Console.WriteLine("promedio : {0}",p);

Console.ReadLine();

}

}

}

4. Hallar el pago de un cliente por la fecha de ingreso ante una empresa, hallando el total de

trabajo, IGV y el pago final.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[]

args)

{

string cliente;

string fdi;

double total, igv, pago;

Console.Write("Cliente :");

cliente = (Console.ReadLine());

Console.Write("Fecha de ingreso :");

fdi = (Console.ReadLine());

Console.Write("total :");

total = double.Parse(Console.ReadLine());

igv = total * (19 / 100.0);

pago = total + igv;

Console.WriteLine("igv :{0}", igv);

Console.WriteLine("pago :{0}", pago);

Console.ReadLine();

}

}

}

Page 6: Ejercicios c#

5. La venta de un producto “x” sacando la cantidad, IGV, pago final

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

string producto;

double cant, precio, total, igv, pagar;

Console.Write("Nombre del producto:");

producto = (Console.ReadLine());

Console.Write("cantidad : ");

cant = double.Parse(Console.ReadLine());

Console.Write("precio : ");

precio = double.Parse(Console.ReadLine());

total = cant * precio;

igv = (19 / 100.0) * total;

pagar = total + igv;

Console.WriteLine("total : {0}", total);

Console.WriteLine("igv : {0}", igv);

Console.WriteLine("pagar :{0}", pagar);

Console.ReadLine();

}

}

}

6. Ingrese un numero de 2 dígitos y mostrando en sentido al reverso.

using System;

using

System.Collections.Generic;

using System.Text;

namespace ConsoleApplication2

{

class Program

{

static void Main(string[] args)

{

int n, c, r, rpta;

Console.Write("Ingrese un numero de 2 digitos :");

n = int.Parse(Console.ReadLine());

c = n / 10;

r = n % 10;

rpta = r * 10 + c;

Console.WriteLine("Numero al reves : {0}", rpta);

Console.ReadLine();

}

}

}

Page 7: Ejercicios c#

7. Intercambia los primeros valores de dos numeros ejemplo

(a=12, b=34, a1=32, b1=14).

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n1, n2, rev1, rev2, res1, res2, can1, can2;

Console.ForegroundColor = ConsoleColor.Red;

Console.Write("Primer Número : ");

n1 = int.Parse(Console.ReadLine());

Console.Write("Segundo Número : ");

n2 = int.Parse(Console.ReadLine());

rev1 = n1 / 10;

res1 = n1 % 10;

rev2 = n2 / 10;

res2 = n2 % 10;

can1 = (rev2 * 10) + res1;

can2 = (rev1 * 10) + res2;

Console.ForegroundColor = ConsoleColor.Blue;

Console.WriteLine("Primer Número Invertido : {0}", can1);

Console.WriteLine("Segundo Número Invertido : {0}", can2);

Console.ReadLine();

}

}

}

Page 8: Ejercicios c#

AAApppllliiicccaaaccciiióóónnn cccooonnn “““MMMAAATTTHHH...””” Ejercicio nº 1

Se ingresa el valor del lado de un cuadrado, ¿calcular su perímetro y su área? Perímetro=4 * lado Área = lado al cuadrado

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication2

{

class Program

{

static void Main(string[] args)

{

double r, diam, lc, area;

Console.Write("ingrese el valor de la radio :");

r = double.Parse(Console.ReadLine());

diam = 2 * r;

lc = 2 * Math.PI * r;

area = Math.PI * r * r;

Console.WriteLine("diametro : {0}", diam);

Console.WriteLine("longitud de la circunferencia :{0}", lc);

Console.WriteLine("area : {0}",area);

Console.ReadLine();

}

}

}

Ejercicio nº 2

En un triángulo rectángulo, las proyecciones de los catetos sobre la hipotenusa miden 4 y 9 metros. ¿Calcular la altura relativa a la hipotenusa?.

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication2

{

class Program

{

static void Main(string[] args)

{

double c1, c2, h;

Console.Write("ingrese cateto 1:");

c1 = double.Parse(Console.ReadLine());

Console.Write("ingrese cateto 2:");

c2 = double.Parse(Console.ReadLine());

h = Math.Sqrt(c1 * c2);

Console.WriteLine("Hipotenusa : {0}", h);

Console.ReadLine();

}

}

PI

√ Raíz

Page 9: Ejercicios c#

} Ejercicio nº 3

Ingresar un número, elevarlo a la potencia determinada, ya sea al cuadrado, al cubo, a la cuarta, etc.

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication2

{

class Program

{

static void Main(string[] args)

{

double n1, p, r;

Console.Write("ingrese un numero :");

n1 = double.Parse(Console.ReadLine());

Console.Write("elevalo a la potencia :");

p = double.Parse(Console.ReadLine());

r = Math.Pow(n1,p);

Console.WriteLine("resultado : {0}", r);

Console.ReadLine();

}

}

}

EJERCICIO Nº 4

Ingresar un valor de logaritmo, luego aplicándolo un número natural para sacar su

resultado final.

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication2

{

class Program

{

static void Main(string[] args)

{

double loga, n1, r;

Console.Write("ingrese logaritmo :");

loga = double.Parse(Console.ReadLine());

Console.Write("ingrese un numero :");

n1 = double.Parse(Console.ReadLine());

r = Math.Log (n1,loga);

Console.WriteLine("resultado : {0}", r);

Console.ReadLine();

}

}

}

Logaritmo

Potencia

Page 10: Ejercicios c#

EJERCICIO Nº 5

Hallar el coseno de un número ingresado en la aplicación de consola

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication2

{

class Program

{

static void Main(string[] args)

{

double n1, r;

Console.Write("ingrese un numero :");

n1 = double.Parse(Console.ReadLine());

r = Math.Cos (n1);

Console.WriteLine("El coseno del numero ingresado es : {0}", r);

Console.ReadLine();

}

}

}

EJERCICIO Nº 6

Aplicamos en una sola operación todo lo aprendido de “MATH.” EN C#.

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication2

{

class Program

{

static void Main(string[] args)

{

double z, x, a, p1, p2, p3;

a = 90;

x = Math.PI * a / 180;

p1 = Math.Pow(Math.Sin(x * x) + Math.Cos(x) * Math.Cos(x), 1 /

4.0);

p2=Math.Pow(Math.Log10(x)/(2*x),1/2.0);

p3 = Math.Log(Math.Pow(x, 4 / 3.0));

z = Math.Pow((p1 + p2) / p3, 1 / 9.0);

Console.WriteLine(" z = {0}",z);

Console.ReadLine();

}

}

}

Coseno

Page 11: Ejercicios c#

AAApppllliiicccaaaccciiióóónnn “““IIIFFF &&& EEELLLSSSEEE”””

EJERCICIO Nº 1

Leer 2 notas de un alumno y mostrar el mensaje según su promedio, “APROBADO” O

“DESAPROBADO”

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

double n1, n2, prom;

Console.Write("ingrese 1º nota :");

n1 = double.Parse(Console.ReadLine());

Console.Write("ingrese 2º nota :");

n2 = double.Parse(Console.ReadLine());

prom = (n1 + n2) / 2;

Console.WriteLine("promedio : {0}", prom);

if (prom >= 10.5)

Console.WriteLine("APROBADO");

else

Console.WriteLine("DESAPROBADO");

Console.ReadLine();

}

}

}

OPERADORES LÓGICOS OPERADORES RELACIONADOS PSEUDOCODIGO C# PSEUDOCODIGO C#

Y && > > O || < <

NO ! >= >= <= <=

= ==

<> !=

No tiene; porque en un c:

Page 12: Ejercicios c#

EJERCICIO Nº 2

Leer 2 notas de un alumno y mostrar el mensaje según su promedio

PROMEDIO MENSAJE 0 - 10.49 DESAPROBADO

10.5 - 13.49 REGULAR 13.50 – 16.49 MUY BIEN

16.5 – 20.00 EXCELENTE

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

double n1, n2, prom;

Console.Write("ingrese 1º nota :");

n1 = double.Parse(Console.ReadLine());

Console.Write("ingrese 2º nota :");

n2 = double.Parse(Console.ReadLine());

prom = (n1 + n2) / 2;

Console.WriteLine("promedio : {0}", prom);

if (prom >= 0 && prom <= 10.49)

Console.WriteLine("DESAPROBADO");

else if (prom >= 10.50 && prom <= 13.49)

Console.WriteLine("REGULAR");

else if (prom >= 13.50 && prom <= 16.49)

Console.WriteLine("MUY BIEN");

else

Console.WriteLine("EXCELENTE");

Console.ReadLine();

}

}

}

Page 13: Ejercicios c#

EJERCICIO Nº 3

Hacer un concurso de un participante en la cual debe de ingresar sus datos, y

sacar una de las 3 “llaves” para que gane un premio.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

string nombre;

string direccion;

int premio;

Console.WriteLine("Ingrese Numero de llave)");

Console.WriteLine("llave (1) llave(2) llave (3)");

Console.Write("Nombre :");

nombre = (Console.ReadLine());

Console.Write("Direccion :");

direccion = (Console.ReadLine());

Console.Write("Numero de llave :");

premio = int.Parse(Console.ReadLine());

if (premio == 1)

Console.WriteLine("GANO S/.10,000 NUEVOS SOLES");

else if (premio == 2)

Console.WriteLine("GANO UNA CASA");

else if (premio == 3)

Console.WriteLine("NO EXISTE PREMIO");

Console.ReadLine();

}

}

}

Page 14: Ejercicios c#

AAApppllliiicccaaaccciiióóónnn cccooonnn “““SSSwwwiiitttccchhh”””

EJERCICIO Nº 1

1. Leer un numero entre 1, 7 y mostrar el dia de la semana que representa.

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n;

string rpta;

rpta = "nro. No esta entre 1 y 7";

Console.Write("ingrese un nro. entre 1 y 7:");

n = int.Parse(Console.ReadLine());

switch (n)

{

case 1: rpta = "lunes"; break;

case 2: rpta = "martes"; break;

case 3: rpta = "miercoles"; break;

case 4: rpta = "jueves"; break;

case 5: rpta = "viernes"; break;

case 6: rpta = "sabado"; break;

case 7: rpta = "domingo"; break;

}

Console.WriteLine("{0}", rpta);

Console.ReadLine();

}

}

}

Ingrese un número entre 1 y 7: 2 Martes

Page 15: Ejercicios c#

2. Leer un numero entre 1, 12 y mostrar el mes de cada año que se representa.

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n;

string rpta = "No Es El Número Correcto";

Console.Write("Ingrese Un Numero Del 1 al 12 : ");

n = int.Parse(Console.ReadLine());

switch (n)

{

case 1: rpta = "Enero"; break;

case 2: rpta = "Febrero"; break;

case 3: rpta = "Marzo"; break;

case 4: rpta = "Abril"; break;

case 5: rpta = "Mayo"; break;

case 6: rpta = "Junio"; break;

case 7: rpta = "Julio"; break;

case 8: rpta = "Agosto"; break;

case 9: rpta = "Setiembre"; break;

case 10: rpta = "Octubre"; break;

case 11: rpta = "Noviembre"; break;

case 12: rpta = "Diciembre"; break;

}

Console.WriteLine("El Mes Es : {0}", rpta);

Console.ReadLine();

}

}

}

Page 16: Ejercicios c#

3. Leer un numero entero pisitivo entre 1 y 99 y muestre su equivalencia en letras.

Ejemplo: 99 = Noventa y Nueve

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, u, d;

string rpta = "";

Console.Write("Ingrese Un Número : ");

n = int.Parse(Console.ReadLine());

d = n / 10;

u = n % 10;

switch (u)

{

case 1: rpta = "Uno"; break;

case 2: rpta = "Dos"; break;

case 3: rpta = "Tres"; break;

case 4: rpta = "Cuatro"; break;

case 5: rpta = "Cinco"; break;

case 6: rpta = "Seis"; break;

case 7: rpta = "Siete"; break;

case 8: rpta = "Ocho"; break;

case 9: rpta = "Nueve"; break;

}

switch (d)

{

case 1: switch (u)

{

case 0: rpta = "Diez"; break;

case 1: rpta = "Once"; break;

case 2: rpta = "Doce"; break;

case 3: rpta = "Trece"; break;

case 4: rpta = "Catorce"; break;

case 5: rpta = "Quince"; break;

default: rpta = "Dieci" + rpta; break;

} break;

case 2: if (u == 0) rpta = "Veinte"; else rpta = "Veinti" + rpta; break;

case 3: if (u == 0) rpta = "Treinta"; else rpta = "Treinta y " + rpta; break;

case 4: if (u == 0) rpta = "Curenta"; else rpta = "Cuarenta y " + rpta; break;

case 5: if (u == 0) rpta = "Cincuenta"; else rpta = "Cincuenta y" + rpta; break;

case 6: if (u == 0) rpta = "Sesenta"; else rpta = "Sesenta y " + rpta; break;

case 7: if (u == 0) rpta = "Setenta"; else rpta = "Setenta y" + rpta; break;

case 8: if (u == 0) rpta = "Ochenta"; else rpta = "Ochenta y " + rpta; break;

case 9: if (u == 0) rpta = "Noventa"; else rpta = "Noventa y " + rpta; break;

}

Console.WriteLine("Numero en Letras : {0}", rpta);

Console.ReadLine();

}

}

}

Page 17: Ejercicios c#

4. Leer un numero entero pisitivo entre 1 y 999 y muestre su equivalencia en letras.

Ejemplo: 999 = Novecientos Noventa y Nueve

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int num, cent, centres, dec, decres, uni;

string u = "", d = "", c = "";

Console.Write("Ingrese numero:");

num = int.Parse(Console.ReadLine());

cent = num / 100;

centres = num % 100;

dec = centres / 10;

decres = centres % 10;

uni = decres;

switch (uni)

{

case 1: u = "Uno "; break;

case 2: u = "Dos "; break;

case 3: u = "Tres "; break;

case 4: u = "Cuatro "; break;

case 5: u = "Cinco "; break;

case 6: u = "Seis "; break;

case 7: u = "Siete "; break;

case 8: u = "Ocho "; break;

case 9: u = "Nueve"; break;

}

switch (dec)

{

case 1: switch (uni)

{

case 0: u = "Diez"; break;

case 1: u = "Once"; break;

case 2: u = "Doce"; break;

case 3: u = "Trece"; break;

case 4: u = "Catorce"; break;

case 5: u = "Quince"; break;

default: u = "Dieci" + u; break;

}

break;

}

switch (dec)

{

case 2: if (uni == 0) d = "Veinte"; else d = "venti "; break;

case 3: if (uni == 0) d = "Treinta"; else d = "Treinta y "; break;

case 4: if (uni == 0) d = "Cuarenta "; else d = "Cuarenta y "; break;

case 5: if (uni == 0) d = "Cincuenta "; else d = "Cincuenta y "; break;

case 6: if (uni == 0) d = "Sesenta "; else d = "Sesenta y "; break;

case 7: if (uni == 0) d = "Setenta "; else d = "Setenta y "; break;

case 8: if (uni == 0) d = "Ocheta "; else d = "Ochenta y "; break;

case 9: if (uni == 0) d = "Noventa "; else d = "Noventa y "; break;

}

switch (cent)

{

case 1: if (uni == 0)

c = "Cien";

else

c = "ciento ";

break;

case 2: c = "Docientos "; break;

case 3: c = "Trecientos "; break;

case 4: c = "Cuatrocientos "; break;

case 5: c = "Quinientos "; break;

case 6: c = "Seiscientos "; break;

case 7: c = "Sietecientos "; break;

case 8: c = "Ochocientos "; break;

case 9: c = "Novecientos "; break;

}

Console.WriteLine("Numero En Letras : {0} ", c + d + u);

Console.ReadLine();

}

}

}

Page 18: Ejercicios c#

5. Leer un numero entero pisitivo entre 1 y 99 y muestre su

equivalencia en ingles.

Ejemplo: 99 = Ninety Nine

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, u, d;

string rpta = "";

Console.Write("Ingrese Un Numero : ");

n = int.Parse(Console.ReadLine());

d = n / 10;

u = n % 10;

switch (u)

{

case 1: rpta = "One"; break;

case 2: rpta = "Two"; break;

case 3: rpta = "Three"; break;

case 4: rpta = "Four"; break;

case 5: rpta = "Five"; break;

case 6: rpta = "Six"; break;

case 7: rpta = "Seven"; break;

case 8: rpta = "Eigth"; break;

case 9: rpta = "Nine"; break;

}

switch (d)

{

case 1: switch (u)

{

case 0: rpta = "ten"; break;

case 1: rpta = "Eleven"; break;

case 2: rpta = "Twuelve"; break;

case 3: rpta = "Thirteen"; break;

case 4: rpta = "Forteen"; break;

case 5: rpta = "Fifteen"; break;

case 6: rpta = "Sixteen"; break;

case 7: rpta = "Seventeen"; break;

case 8: rpta = "Eighteen"; break;

case 9: rpta = "Nineteen"; break;

}

break; case 2: if (u == 0) rpta = "Twenty"; else rpta = "Twenty " + rpta; break;

case 3: if (u == 0) rpta = "Thirty"; else rpta = "Thirty " + rpta; break;

case 4: if (u == 0) rpta = "Forty"; else rpta = "Forty " + rpta; break;

case 5: if (u == 0) rpta = "Fifty"; else rpta = "Fifty " + rpta; break;

case 6: if (u == 0) rpta = "Sixty"; else rpta = "Sixty " + rpta; break;

case 7: if (u == 0) rpta = "Seventy"; else rpta = "Seventy " + rpta; break;

case 8: if (u == 0) rpta = "Eigthy"; else rpta = "Eigthy " + rpta; break;

case 9: if (u == 0) rpta = "Ninety"; else rpta = "Ninety " + rpta; break;

}

Console.WriteLine("Numero En Ingles : {0}", rpta);

Console.ReadLine();

}

}

}

Page 19: Ejercicios c#

6. Leer un numero entero pisitivo entre 1 y 999 y muestre su

equivalencia en ingles.

Ejemplo: 999 = Nine Hundred Ninety Nine

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, u, d, d1, c, c1;

string un = "", dec = "", cen = "";

Console.Write("Ingrese Un Numero : ");

n = int.Parse(Console.ReadLine());

c = n / 100;

c1 = n % 100;

d = c1/ 10;

d1 = c1 % 10;

u = d1;

switch (u)

{

case 1: un = "One"; break;

case 2: un = "Two"; break;

case 3: un = "Three"; break;

case 4: un = "Four"; break;

case 5: un = "Five"; break;

case 6: un = "Six"; break;

case 7: un = "Seven"; break;

case 8: un = "Eigth"; break;

case 9: un = "Nine"; break;

}

switch (d)

{

case 1: switch (u)

{

case 0: un = "ten"; break;

case 1: un = "Eleven"; break;

case 2: un = "Twuelve"; break;

case 3: un = "Thirteen"; break;

case 4: un = "Forteen"; break;

case 5: un = "Fifteen"; break;

case 6: un = "Sixteen"; break;

case 7: un = "Seventeen"; break;

case 8: un = "Eighteen"; break;

case 9: un = "Nineteen"; break;

}

break;

case 2: if (u == 0) dec = "Twenty"; else dec = "Twenty "; break;

case 3: if (u == 0) dec = "Thirty"; else dec = "Thirty "; break;

case 4: if (u == 0) dec = "Forty"; else dec = "Forty "; break;

case 5: if (u == 0) dec = "Fifty"; else dec = "Fifty "; break;

case 6: if (u == 0) dec = "Sixty"; else dec = "Sixty "; break;

case 7: if (u == 0) dec = "Seventy"; else dec = "Seventy "; break;

case 8: if (u == 0) dec = "Eigthy"; else dec = "Eigthy "; break;

case 9: if (u == 0) dec = "Ninety "; else dec = "Ninety "; break;

}

switch (c)

{

case 1: cen = "Hundred "; break;

case 2: cen = "Two Hundred "; break;

case 3: cen = "THree Hundred "; break;

case 4: cen = "Four Hundred "; break;

case 5: cen = "Five Hundred "; break;

case 6: cen = "Six Hundred "; break;

case 7: cen = "Seven Hundred "; break;

case 8: cen = "Eigth Hundred "; break;

case 9: cen = "Nine Hundred "; break;

}

Console.WriteLine("Numero En Ingles : {0}", cen + dec + un);

Console.ReadLine();

}

}

Page 20: Ejercicios c#

}

7. Leer un numero entero pisitivo entre 1 y 9999 y muestre su equivalencia en ingles.

Ejemplo: 999 = Nine Thousand Nine Hundred Ninety Nine

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, u, d, d1, c, c1, mi, mi1; string un = "", dec = "", cen = "", mil = "";

Console.Write("Ingrese Un Numero : ");

n = int.Parse(Console.ReadLine());

mi = n / 1000;

mi1 = n % 1000;

c = mi1 / 100;

c1 = mi1 % 100;

d = c1 / 10;

d1 = c1 % 10;

u = d1;

switch (u) {

case 1: un = "One"; break;

case 2: un = "Two"; break;

case 3: un = "Three"; break;

case 4: un = "Four"; break;

case 5: un = "Five"; break;

case 6: un = "Six"; break;

case 7: un = "Seven"; break;

case 8: un = "Eigth"; break;

case 9: un = "Nine"; break;

}

switch (d)

{

case 1: switch (u)

{

case 0: un = "Ten"; break;

case 1: un = "Eleven"; break;

case 2: un = "Twuelve"; break;

case 3: un = "Thirteen"; break;

case 4: un = "Forteen"; break;

case 5: un = "Fifteen"; break;

case 6: un = "Sixteen"; break;

case 7: un = "Seventeen"; break;

case 8: un = "Eighteen"; break;

case 9: un = "Nineteen"; break;

}

break;

case 2: if (u == 0) dec = "Twenty"; else dec = "Twenty "; break;

case 3: if (u == 0) dec = "Thirty"; else dec = "Thirty "; break;

case 4: if (u == 0) dec = "Forty"; else dec = "Forty "; break;

case 5: if (u == 0) dec = "Fifty"; else dec = "Fifty "; break;

case 6: if (u == 0) dec = "Sixty"; else dec = "Sixty "; break;

case 7: if (u == 0) dec = "Seventy"; else dec = "Seventy "; break;

case 8: if (u == 0) dec = "Eigthy"; else dec = "Eigthy "; break;

case 9: if (u == 0) dec = "Ninety "; else dec = "Ninety "; break;

}

switch (c)

{

case 1: cen = "Hundred "; break;

case 2: cen = "Two Hundred "; break;

case 3: cen = "THree Hundred "; break;

case 4: cen = "Four Hundred "; break;

case 5: cen = "Five Hundred "; break;

case 6: cen = "Six Hundred "; break;

case 7: cen = "Seven Hundred "; break;

case 8: cen = "Eigth Hundred "; break;

case 9: cen = "Nine Hundred "; break;

}

switch (mi)

{

case 1: mil = "Thousand "; break;

case 2: mil = "Two Thousand "; break;

case 3: mil = "Three Thousand "; break;

case 4: mil = "Four Thousand "; break;

case 5: mil = "Five Thousand "; break;

case 6: mil = "Six Thousand "; break;

case 7: mil = "Seven Thousand "; break;

case 8: mil = "Eight Thousand "; break;

case 9: mil = "Nine Thousand "; break;

}

Page 21: Ejercicios c#

Console.WriteLine("Numero En Ingles : {0}", mil + cen + dec + un);

Console.ReadLine();

}

}

}

8. convertir de un numero natural a un numero romano.

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int num,cent,centres,dec,decres,uni;

string u = "",d="",c="";

Console.Write("Ingrese numero :");

num = int.Parse(Console.ReadLine());

cent = num / 100;

centres = num % 100;

dec = centres / 10;

decres=centres % 10;

uni = decres;

switch (uni) {

case 1: u = "I"; break;

case 2: u = "II"; break;

case 3: u = "III"; break;

case 4: u = "IV"; break;

case 5: u = "V"; break;

case 6: u = "VI"; break;

case 7: u = "VII"; break;

case 8: u = "VIII"; break;

case 9: u = "IX"; break;

}

switch (dec)

{

case 1: d = "X"; break;

case 2: d = "XX"; break;

case 3: d = "XXX"; break;

case 4: d = "XL"; break;

case 5: d = "L"; break;

case 6: d = "LX"; break;

case 7: d = "LXX"; break;

case 8: d = "LXXX"; break;

case 9: d = "XC"; break;

}

switch (cent) {

case 1: c = "C"; break;

case 2: c = "CC"; break;

case 3: c = "CCC"; break;

case 4: c = "CD"; break;

case 5: c = "D"; break;

case 6: c = "DC"; break;

case 7: c = "DCC"; break;

case 8: c = "DCCC"; break;

case 9: c = "CM"; break;

}

Console.WriteLine("Numero en romanos :{0}", c + d + u);

Console.ReadLine();

}

}

}

Page 22: Ejercicios c#

AAApppllliiicccaaaccciiióóónnn cccooonnn “““FFFOOORRR”””

1. Ingrese 5 numeros sucesivos, alicando for.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int i;

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

{

Console.WriteLine("Ingrese Numero: {0} ", i);

}

Console.ReadLine();

}

}

}

2. Ingrese 5 textos “Erick”.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int i;

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

{

Console.WriteLine("{0} Erick ", i);

}

Console.ReadLine();

}

}

}

Page 23: Ejercicios c#

3. Ingrese n numeros, de forma sucesiva.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int i,n;

Console.Write("Ingese Valor :");

n = int.Parse(Console.ReadLine());

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

{

Console.WriteLine("Numero Ingresado : {0} ", i);

}

Console.ReadLine();

}

}

}

4. Ingrese n textos “Leon”, aplicando for.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int i,n;

Console.Write("Ingese Valor :");

n = int.Parse(Console.ReadLine());

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

{

Console.WriteLine("{0} Leon ", i);

}

Console.ReadLine();

}

}

}

Page 24: Ejercicios c#

5. Aplicando for halla la suma de n numeros.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int i, n, suma, suma1;

suma1 = 0;

Console.Write("ingrese valor:");

n = int.Parse(Console.ReadLine());

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

{

Console.Write("{0}º Numero :", i);

suma = int.Parse(Console.ReadLine());

suma1 = suma + suma1;

}

Console.WriteLine("Resultado de la Suma : {0}", suma1);

Console.ReadLine();

}

}

}

6. Hallar las 7 notasde un alumno y sacar promedio

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication2

{

class Program

{

static void Main(string[] args)

{

int nota, suma, i;

double prom;

suma = 0;

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

{

Console.Write("ingrese nota {0}:", i);

nota = int.Parse(Console.ReadLine());

suma = suma + nota;

}

prom = suma / 7.0; Console.WriteLine("el promedio es : {0}", prom);

Console.ReadLine();

}

}

}

Page 25: Ejercicios c#

7. Leer 10 números y hallar el mayor

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication3

{

class Program

{

static void Main(string[] args)

{

int n, i, max;

max = 0;

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

{

Console.Write("ingrese nro {0}:", i);

n = int.Parse(Console.ReadLine());

if (i == 1)

max = n;

if (n > max)

max = n;

}

Console.WriteLine("Numero mayor: {0}", max);

Console.ReadLine();

}

}

}

8. Leer 10 números y hallar el menor

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication3

{

class Program

{

static void Main(string[] args)

{

int n, i, mim;

mim = 0;

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

{

Console.Write("ingrese nro {0}:", i);

n = int.Parse(Console.ReadLine());

if (i == 1)

mim = n;

if (n < mim)

mim = n;

}

Console.WriteLine("Numero menor: {0}", mim);

Console.ReadLine();

}

}

}

Page 26: Ejercicios c#

9. Leer 10 números y mostrar cuantos son positivos y cuántos son negativos y mostrar cuantos ceros hay.

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication3

{

class Program

{

static void Main(string[] args)

{

int n,i,cp,cn,cc;

cp=0;

cn=0;

cc=0;

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

{

Console.Write("ingrese nro {0}:", i);

n = int.Parse(Console.ReadLine());

if (n < 0)

cn = cn + 1;

else if (n > 0)

cp = cp + 1;

else

cc = cc + 1;

}

Console.WriteLine("Cantidad de positivo: {0}", cp);

Console.WriteLine("cantidad de negativo: {0}", cn);

Console.WriteLine("cantidad de ceros : {0}", cc);

Console.ReadLine();

}

}

}

10. Dado un rango numerico entero.inicial y numerico entero. Final, obtener la cantidad de

numeros positivos y negativos que existen en el rango.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int ni, nf, i, cp = 0, cn = 0;

Console.Write("Numero Inicial : ");

ni = int.Parse(Console.ReadLine());

Console.Write("Numero Final : ");

nf = int.Parse(Console.ReadLine());

for (i = ni; i <= nf; i++)

{

Console.WriteLine("{0}", i);

if (i < 0)

cn = cn + 1;

else if (i > 0)

cp = cp + 1;

}

Console.WriteLine("Cantidad de Positivos : {0}", cp);

Console.WriteLine("Cantidad de negativos : {0}", cn);

Console.ReadLine();

}

}

}

Page 27: Ejercicios c#

11. Ingresar dos numeros “primer numero” y “segundo numero”, mostrando sucesivamente hasta el “segundo numero”

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int indice, indice2, a, b;

Console.Write("Ingrese el primer numero : ");

indice = int.Parse(Console.ReadLine());

Console.Write("Ingrese el segundo numero : ");

indice2 = int.Parse(Console.ReadLine());

for (int i = indice; i <= indice2; i++)

Console.WriteLine("{0}", i);

Console.ReadLine();

}

}

}

12. Ingresar un numero, automáticamente que muestre los siguientes numero sucesivos pares

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int indice;

Console.Write("Ingrese cantidad :");

indice = int.Parse(Console.ReadLine());

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

if (i % 2 == 0)

Console.WriteLine(i);

Console.ReadLine();

}

}

}

Page 28: Ejercicios c#

13. Dado un rango de números enteros, obtener la cantidad de números enteros que contiene

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int i, ni, nf, can;

Console.Write("numero Inicial : ");

ni = int.Parse(Console.ReadLine());

Console.Write("Numero Final : ");

nf = int.Parse(Console.ReadLine());

ni = ni + 1;

nf = nf - 1;

for (i = ni; i <= nf; i++)

Console.WriteLine("{0}", i);

can = nf - ni + 1;

Console.WriteLine("Cantidad : {0}", can);

Console.ReadLine();

}

}

}

14. Hallar la suma y el producto de n numeros que son pares

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, i, s = 0, p = 1;

Console.Write("Ingrese Cantidad : ");

n = int.Parse(Console.ReadLine());

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

{

Console.WriteLine(i * 2);

s = s + i * 2;

p = p * i * 2;

}

Console.WriteLine("suma : {0}", s);

Console.WriteLine("Producto : {0}", p);

Console.ReadLine();

}

}

}

Page 29: Ejercicios c#

15. Ingresar un número y mostrar sucesivamente ordenado sucesivamente hasta l legar al número

indicado.

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int indice,o=1;

Console.Write("Ingrese cantidad :");

indice = int.Parse(Console.ReadLine());

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

Console.WriteLine(o+"/"+(i));

Console.ReadLine();

}

}

}

16. Ingresar un número y mostrar los números sucesivos indicados al número ingresado

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int indice,o=1;

Console.Write("Ingrese cantidad :");

indice = int.Parse(Console.ReadLine());

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

Console.WriteLine(i+ "+" + (i+1) +"/"+(i+2));

Console.ReadLine();

}

}

}

Page 30: Ejercicios c#

17. Hallar la tabla de multiplicar hasta el 12, ingresando un numero “x”

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int indice;

Console.Write("Ingrese un numero :");

indice = int.Parse(Console.ReadLine());

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

Console.WriteLine("{0}*{1}={2}",i,indice,i*indice);

Console.ReadLine();

}

}

}

18. Hallar la tabla de multiplicar del 10 * 12, siendo sucesivamente del 1 hasta el 10

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

//int indice;

//Console.Write("Ingrese cantidad :");

//indice = int.Parse(Console.ReadLine());

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

for (int j = 1; j <= 12;j++ )

Console.WriteLine("{0}*{1}={2}", i, j, i * j);

Console.ReadLine();

}

}

}

Page 31: Ejercicios c#

19. Mostrar los números del 1 al 20, en excepción de los múltiplos de tres

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

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

{

if (i % 3 == 0) continue;

Console.WriteLine(i);

}

Console.ReadLine();

}

}

}

Page 32: Ejercicios c#

20. Una persona debe realizar un muestreo con 50 personas para determinar el promedio de peso de los niños jóvenes adultos y viejos que existen en su zona habitacional. Se determinan las categorías con base

en la siguiente tabla.

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication3

{

class Program

{

static void Main(string[] args)

{

int i, ni, jo, ad, vi, edad;

double peso, pn, pj, pa, pv, ppn, ppa,

ppj, ppv;

ni = 0;

jo = 0;

ad = 0;

vi = 0;

pn = 0;

pj = 0;

pa = 0;

pv = 0;

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

{

Console.Write("ingrese edad:");

edad = int.Parse(Console.ReadLine());

Console.Write("ingrese peso:");

peso = double.Parse(Console.ReadLine());

if (edad >= 0 && edad <= 12)

{

pn = pn + peso;

ni = ni + 1;

}

else if (edad >= 13 && edad <= 29)

{

pj = pj + peso;

jo = jo + 1;

}

else if (edad >= 30 && edad <= 59)

{

pa = pa + peso;

ad = ad + 1;

}

else if (edad >= 60 && edad < 100)

{

pv = pv + peso;

vi = vi + 1;

}

}

if (ni > 0)

{

ppn = pn / ni;

Console.WriteLine("x peso niños:{0}", ppn);

}

if (jo > 0)

{

ppj = pj / jo;

Console.WriteLine("x peso jovenes: {0}", ppj);

}

if (ad > 0)

{

ppa = pa / ad;

Console.WriteLine("x peso adulto;{0}", ppa);

}

if (vi > 0)

{

ppv = pv / vi;

Console.WriteLine("x peso de viejo: {0}", ppv);

}

Console.ReadLine();

}

}

}

Cambiar Nº

Page 33: Ejercicios c#

21. Aplicar un FOR dentro de otro FOR

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int cf;

Console.Write("Cantidad de Facturas: ");

cf = int.Parse(Console.ReadLine());

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

{

Console.WriteLine("");

Console.WriteLine("Factura Número{0}",i);

Console.WriteLine("Detalle de Facturas");

for (int j = 1; j <= 3; j++)

{

Console.WriteLine("Linea de detalle(0)", j);

}

}

Console.ReadLine();

}

}

}

Page 34: Ejercicios c#

AAApppllliiicccaaaccciiióóónnn cccooonnn “““AAARRRRRREEEGGGLLLOOOSSS”””

1. Ingresar n números en arreglos

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, i;

int[] x = new int[20];

Console.Write("Ingrese cantidad : ");

n = int.Parse(Console.ReadLine());

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

{

Console.Write("Ingrese numero :");

x[i] = int.Parse(Console.ReadLine());

}

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

{

Console.WriteLine("Numero : x[" + i + "]:{0}", x[i]);

}

Console.ReadLine();

}

}

}

2. Hallar la suma de n números en arreglos

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, i, sum=0;

int[] x = new int[20];

Console.Write("Ingrese Cantidad : ");

n = int.Parse(Console.ReadLine());

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

{

Console.Write("Ingrese Numero : ");

x[i] = int.Parse(Console.ReadLine());

sum = sum + x[i];

}

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

{

Console.WriteLine("Numero : x[" + i + "] : {0}", x[i]);

}

Console.WriteLine("Suma : {0}", sum);

Console.ReadLine();

}

}

Page 35: Ejercicios c#

}

3. Hallar el producto de n números en arreglos

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, i, pro=1;

int[] x = new int[20];

Console.Write("Ingrese Cantidad : ");

n = int.Parse(Console.ReadLine());

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

{

Console.Write("Ingrese Numero : ");

x[i] = int.Parse(Console.ReadLine());

pro = pro * x[i];

}

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

{

Console.WriteLine("Numero : x[" + i + "] : {0}", x[i]);

}

Console.WriteLine("Producto : {0}", pro);

Console.ReadLine();

}

}

}

4. Ingresar n números en un arreglo y encontrar el número menor.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, i, min;

int[] x = new int[20];

Console.Write("Ingrese Cantidad : ");

n = int.Parse(Console.ReadLine());

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

{

Console.Write("Ingrese Numero : ");

x[i] = int.Parse(Console.ReadLine());

}

min = x[0];

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

{

if (x[i] < min)

min = x[i];

}

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

{

Console.WriteLine("Numero : x[" + i + "] : {0}", x[i]);

}

Console.WriteLine("Minimo : {0}",min);

Console.ReadLine();

}

Page 36: Ejercicios c#

}

}

5. Ingresar n numeros y encontrar el numero mayor.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, i, max;

int[] x = new int[20];

Console.Write("Ingrese Cantidad : ");

n = int.Parse(Console.ReadLine());

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

{

Console.Write("Ingrese Numero : ");

x[i] = int.Parse(Console.ReadLine());

}

max = x[0];

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

{

if (x[i] > max)

max = x[i];

}

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

{

Console.WriteLine("Numero : x[" + i + "] : {0}", x[i]);

}

Console.WriteLine("Maximo : {0}", max);

Console.ReadLine();

}

}

}

Page 37: Ejercicios c#

6. Ingresar n numeros y buscar el numero deseado caso

contrario no encontrado.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, i, sw, num;

int[] x = new int[20];

Console.Write("Ingrese Cantidad : ");

n = int.Parse(Console.ReadLine());

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

{

Console.Write("Ingrese Numero : ");

x[i] = int.Parse(Console.ReadLine());

}

sw = 0;

Console.Write("Que Numero Desea Buscar : ");

num = int.Parse(Console.ReadLine());

for (i = 0; i < num; i++)

{

if (x[i] == num)

{

sw = 1;

Console.WriteLine("Numero Encontrado : {0}", num);

Console.WriteLine("Posicion : {0}", i);

}

}

if (sw == 0)

Console.WriteLine("Numero No Encontrado");

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

{

Console.WriteLine("Numero : x[" + i + "] : {0}", x[i]);

}

Console.ReadLine();

}

}

}

Page 38: Ejercicios c#

7. Hallar un arrgelo con todo lo aprendido, suma,

producto,numero maximo, numero mino, y buscar el numero

deseado.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, i, sum = 0, pro = 1, max, min, sw, num;

int[] x = new int[20];

Console.Write("Ingrese Cantidad : ");

n = int.Parse(Console.ReadLine());

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

{

Console.Write("Ingrese Numero : ");

x[i] = int.Parse(Console.ReadLine());

sum = sum + x[i];

pro = pro * x[i];

}

max = x[0];

min = x[0];

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

{

if (x[i] > max)

max = x[i];

if (x[i] < min)

min = x[i];

}

sw = 0;

Console.Write("Que numero desea buscar : ");

num = int.Parse(Console.ReadLine());

for (i = 0; i < num; i++)

{

if (x[i] == num)

{

sw = 1;

Console.WriteLine("Numero Encontrado : {0}", num);

Console.WriteLine("Posicion : {0}", i);

}

}

if (sw == 0)

Console.WriteLine("Numero No Encontrado");

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

{

Console.WriteLine("Numero : x[" + i + "] : {0}", x[i]);

}

Console.WriteLine("Suma : {0}", sum);

Console.WriteLine("Producto : {0}", pro);

Console.WriteLine("Minimo : {0}", min);

Console.WriteLine("Maximo : {0}", max);

Console.ReadLine();

}

}

}

Page 39: Ejercicios c#

AAApppllliiicccaaaccciiióóónnn cccooonnn “““WWWHHHIIILLLEEE YYY DDDOOO”””

Ejercicio nº 1

1. Ingresar del Numero 1 al 10

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int i;

i = 1;

while (i <= 10)

{

Console.WriteLine("{0}", i);

i = i + 1;

}

Console.ReadLine();

}

}

}

Ejercicio nº 2

2. Ingresar del 1 al 10

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int i;

i = 1;

do

{

Console.WriteLine("{0}", i);

i = i + 1;

} while (i <= 10);

Console.ReadLine();

}

}

}

Page 40: Ejercicios c#

Ejercicio nº 3

3. Ingresar en numero del 1 al 999, aplicando el enter

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int i;

i = 11;

while (i <= 999)

{

Console.WriteLine("{0}", i);

Console.ReadLine();

i = i + 1;

}

Console.ReadLine();

}

}

}

Ejercicio nº 4

4. Ingresar el número del 1 al 999 aplicando el enter

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int i;

i = 1;

do

{

Console.WriteLine("{0}", i);

i = i + 1;

Console.ReadLine();

} while (i <= 999);

Console.ReadLine();

}

}

}

Page 41: Ejercicios c#

Ejercicio nº 5

5. Leer un número y mostrar en pantalla si es primo o no mostrar con una respuesta

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, i; string rpta; char seguir;

do

{

Console.Write("ingrese un numero:");

n = int.Parse(Console.ReadLine());

rpta = " ES PRIMO";

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

if (n % i == 0)

{

rpta = "NO ES PRIMO";

break;

}

Console.WriteLine("{0}", rpta);

Console.WriteLine("desea continuar (s/n):"); seguir =

char.Parse(Console.ReadLine());

} while (seguir == 's' || seguir == 's');

}

}

}

Page 42: Ejercicios c#

Ejercicio nº 6

Se presentar 3 alumnos para hacer delegados del salón:

6. HARRY, ATON Y MEDINA. Leer voto por voto y mostrar el porcentaje que obtuvo cada

uno considerando solo los votos validos. También imprimir el nombre del ganador. No

se conoce de ante mano cuantas personas van a votar.

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int cv1, cv2, cv3, voto, max;

double total, pv1, pv2, pv3;

string ganador;

Console.WriteLine("(1) Harry (2) Anton");

Console.WriteLine("(3) Medina (4) fin");

cv1=0;cv2=0;cv3=0;

do

{

Console.Write("ingrese voto:");

voto = int.Parse(Console.ReadLine());

if (voto == 1)

cv1 = cv1 + 1;

else if (voto == 2)

cv2 = cv2 + 1;

else if (voto == 3)

cv3 = cv3 + 1;

} while (voto != 4);

total = cv1 + cv2 + cv3;

pv1=(cv1/total)*100;

pv2=(cv2/total)*100;

pv3=(cv3/total)*100;

Console.WriteLine("Harry:{0}",pv1);

Console.WriteLine("Anton:{0}",pv2);

Console.WriteLine("Medina:{0}",pv3);

max = cv1;

ganador ="Harry";

if (cv2>max)

{ max=cv2;

ganador="Anton";

}

if (cv3>max)

{

max =cv3;

ganador="Medina";

}

Console.WriteLine("Felicidades:{0}", ganador);

Console.ReadLine ();

}

}

Page 43: Ejercicios c#

Ejercicio nº 7

7. Leer varios números, hasta que el usuario ingrese CERO. Muestre Cuantos números

ingresó y su promedio.

using System;

using System.Collections.Generic;

using System.Text;

namespace ConsoleApplication1

{

class Program

{

static void Main(string[] args)

{

int n, cont;

double suma, prom;

suma = 0; cont = 0;

do

{

Console.Write("ingrese un numero:");

n = int.Parse(Console.ReadLine());

cont = cont + 1;

suma = suma + 1;

} while (n != 0);

prom = suma / (cont - 1);

Console.WriteLine("cantidad de numeros: {0}", cont - 1);

Console.WriteLine("promedio: {0}", prom);

Console.ReadLine();

}

}

}

Ingrese número: 7 Ingrese número: 2 Ingrese número: 6 Ingresé número: 0 Cantidad de números: 3 Promedio: 5

Page 44: Ejercicios c#

AAApppllliiicccaaaccciiióóónnn cccooonnn “““WWWHHHIIILLLEEE YYY DDDOOO”””

1. Creación de un semáforo

using System;

using System.Threading;

class Program

{

static void Main(string[] args)

{

Semaforo.Iniciar();

}

}

class Semaforo

{

public static void Iniciar()

{

new Thread(new Semaforo().Run).Start();

}

private void Run()

{

while (true)

{

Console.Title="Erick";

Console.Clear();

Console.ForegroundColor=ConsoleColor.Red;

Console.WriteLine("0");

Console.ForegroundColor=ConsoleColor.DarkGray;

Console.WriteLine("0\n0");

Thread.Sleep(3000);

Console.Clear();

Console.WriteLine("0");

Console.ForegroundColor=ConsoleColor.Yellow;

Console.WriteLine("0");

Console.ForegroundColor=ConsoleColor.DarkGray;

Console.WriteLine("0");

Thread.Sleep(500);

Console.Clear();

Console.WriteLine("0\n0");

Console.ForegroundColor=ConsoleColor.Green;

Console.WriteLine("0");

Thread.Sleep (3000);

}

}

}