Está en la página 1de 186

Contenido

INVERTIR NÚMERO DE DOS CIFRAS ................................................................................................ 1


INVERTIR NÚMERO DE TRES CIFRAS ............................................................................................... 2
OPERACIONES BÁSICAS ................................................................................................................... 3
COMPRA EN RESTAURANT .............................................................................................................. 5
FUNCIONES BÁSICAS LIBRERÍA MATH............................................................................................. 6
FORMATOS DE SALIDA .................................................................................................................... 7
EJERCICIO PROPUESTO.................................................................................................................... 9
MAYOR DE DOS NÚMEROS ........................................................................................................... 10
MAYOR DE TRES NÚMEROS .......................................................................................................... 12
DESGLOSE DE BILLETES ................................................................................................................. 13
BONO DEL EMPLEADO POR HIJO .................................................................................................. 15
NÚMERO INTERMEDIO ................................................................................................................. 16
TARIFA TELEFÓNICA ...................................................................................................................... 18
TRIÁNGULOS ................................................................................................................................. 19
EJERCICIO PROPUESTO.................................................................................................................. 20
DÍA DE LA SEMANA ....................................................................................................................... 22
ESTADO CIVIL................................................................................................................................. 24
CALIFICACIÓN ................................................................................................................................ 25
EJERCICIO PROPUESTO.................................................................................................................. 27
TABLA DE MULTIPLICAR ................................................................................................................ 29
PRESUPUESTO ANUAL EN AREAS HOSPITAL ................................................................................. 30
SUMA DE N NÚMEROS PARES E IMPARES .................................................................................... 32
TABLAS DE MULTIPLICAR .............................................................................................................. 33
SUMA DE N NÚMEROS.................................................................................................................. 35
MAYOR Y MENOR DE N NÚMEROS ............................................................................................... 36
SERIE DE FIBONACCI...................................................................................................................... 38
CALIFICACIONES DE UN GRUPO DE ESTUDIANTES........................................................................ 39
NÚMEROS ALEATORIOS Y CARACTERES ASCII .............................................................................. 41
FUNCIONES DE CADENA................................................................................................................ 42
SIMULACIÓN DE UN RELOJ DIGITAL.............................................................................................. 44
CANTIDAD DE VOCALES CERRADAS .............................................................................................. 46
ESTADISTICA POR VOCAL .............................................................................................................. 47

1
Ing. Patricio Medina
FACTORIAL DE UN NÚMERO ......................................................................................................... 49
SERIE DE UN NÚMERO .................................................................................................................. 50
SUCESIÓN DE N CUADROS ............................................................................................................ 52
MOVIMIENTO DE UNA FRASE ....................................................................................................... 53
MOVIMIENTO CARÁCTER POR CARÁCTER HORIZONTAL .............................................................. 55
MOVIMIENTO CARÁCTER POR CARÁCTER VERTICAL.................................................................... 57
EJERCICIO PROPUESTO.................................................................................................................. 59
TABLA DE MULTIPLICAR CON WHILE ............................................................................................ 60
TABLAS DE MULTIPLICAR CON WHILE........................................................................................... 62
COMPROBAR SI ES NÚMERO PRIMO ............................................................................................ 63
FACTORES PRIMOS DE UN NÚMERO ............................................................................................ 65
GENERAR N NÚMEROS PRIMOS.................................................................................................... 66
EJERCICIO PROPUESTOS................................................................................................................ 68
VERIFICACIÓN DE UNA CLAVE 3 OPORTUNIDADES ...................................................................... 69
GENERAR UN NÚMERO ALEATORIO ENTRE 10 Y 30 ..................................................................... 71
JUEGO ADIVINA UN NÚMERO....................................................................................................... 72
CONTROL DE UNA FACTURA ......................................................................................................... 74
VOTACIONES POR SECTOR ............................................................................................................ 76
PROMEDIO DE SUELDOS CERO O NEGATIVO SALE ....................................................................... 77
FRASE INVERTIDA CON WHILE ...................................................................................................... 79
EJERCICIO PROPUESTO.................................................................................................................. 80
TEMA: MANIPULACIÓN DE UN ARREGLO ..................................................................................... 82
INTERCALACIÓN MAYUSCULAS Y MINUSCULAS ........................................................................... 84
GENERAR NÚMEROS ALETORIOS EN UN ARREGLO ...................................................................... 86
PASAR UNA FRASE A UN ARREGLO ............................................................................................... 88
SUMA ELEMENTOS PARES E IMPARES EN UN ARREGLO .............................................................. 89
MAYOR Y MENOR DE UN ARREGLO DE N ELEMENTOS................................................................. 91
OBTENER EL DÍGITO VERIFICADOR DE LA CÉDULA ....................................................................... 93
INSERTAR UN ELEMENTO EN UN ARREGLO .................................................................................. 95
ELIMINAR UN ELEMENTO EN UN ARREGLO.................................................................................. 97
SUMA DE DOS ARREGLOS DE 5 ELEMENTOS ................................................................................ 99
SUMA DE DOS ARREGLOS DE 5 ELEMENTOS INTERCALADO ...................................................... 101
EJERCICIO PROPUESTO................................................................................................................ 103

2
Ing. Patricio Medina
EJERCICIO PROPUESTO................................................................................................................ 105
NÚMERO DECIMAL A BINARIO.................................................................................................... 107
NÚMERO DECIMAL A OCTAL....................................................................................................... 109
NÚMERO DECIMAL A HEXADECIMAL.......................................................................................... 111
EJERCICIO PROPUESTO................................................................................................................ 114
ORDENAMIENTO DE UN ARREGLO MÉTODO BURBUJA ............................................................. 117
BÚSQUEDA DE UN ELEMENTO EN UN ARREGLO ........................................................................ 119
BÚSQUEDA BINARIA DE UN ELEMENTO EN UN ARREGLO.......................................................... 121
EJERCICIO PROPUESTO................................................................................................................ 123
TABLAS DE MULTIPLICAR EN UNA MATRIZ DE NxN .................................................................... 125
GENERAR ALEATORIOS EN UNA MATRIZ DE 5x5 ........................................................................ 127
SUMAR ELEMENTOS DE UNA MATRIZ DE NxN ........................................................................... 128
SUMAR ELEMENTOS DE FILA Y UNA COLUMNA MATRIZ DE 5x5................................................ 130
SUMAR ELEMENTOS DE DIAGONAL PRINCIPAL Y SECUNDARIA ................................................. 131
MATRIZ DE NxN ........................................................................................................................... 131
FORMAR LA LETRA A EN UNA MATRIZ DE NxN........................................................................... 133
EJERCICIO PROPUESTO................................................................................................................ 135
FORMAR LA LETRA R EN UNA MATRIZ DE NxN ........................................................................... 138
SUMAR ELEMENTOS DE DIAGONAL PRINCIPAL Y SECUNDARIA ................................................. 140
MATRIZ DE NxN ........................................................................................................................... 140
NÚMERO MAYOR Y MENOR EN UNA MATRIZ DE NxN ............................................................... 142
ORDENAMIENTO DE UNA MATRIZ DE NxN................................................................................. 144
SUMA DE MATRICES DE 5x5........................................................................................................ 146
MULTIPLICACIÓN DE MATRICES DE 4x4...................................................................................... 148
EJERCICIO PROPUESTO................................................................................................................ 150
GENERACIÓN DEL TRÍANGULO DE PASCAL FORMA 1 ................................................................. 152
GENERACIÓN DEL TRÍANGULO DE PASCAL FORMA 2 ................................................................. 153
MATRIZ TRANSPUESTA DE NxN................................................................................................... 155
MAYORES DE CADA FILA DE UNA MATRIZ NxN EN UN VECTOR ................................................. 157
MENORES DE CADA COLUMNA DE UNA MATRIZ NxN EN UN VECTOR ...................................... 158
PROMEDIOS DE CADA COLUMNA DE UNA MATRIZ NxN EN UN................................................. 160
VECTOR........................................................................................................................................ 160
VOTACIONES. SUMA DE CADA COLUMNA REPRESENTA A UN................................................... 162

3
Ing. Patricio Medina
CANDIDATO OBTENER EL CANDIDATO GANADOR...................................................................... 162
CUBO DE UN NÚMERO................................................................................................................ 164
MAYOR DE TRES NÚMEROS ........................................................................................................ 165
VALOR ABSOLUTO DE UN NÚMERO ........................................................................................... 167
FACTORIAL DE UN NÚMERO ....................................................................................................... 168
INVERTIR UNA FRASE .................................................................................................................. 169
COMPROBAR SI UN NÚMERO ES MÚLTIPLO DE OTRO ............................................................... 171
NÚMERO A QUE DÍA DE LA SEMANA CORRESPONDE................................................................. 172
NÚMERO COMPROBAR SI ES PRIMO .......................................................................................... 174
MENOR EN UN ARREGLO ............................................................................................................ 176
TRANSFORMAR NÚMERO DECIMAL A BINARIO ......................................................................... 177
EJERCICIO PROPUESTO................................................................................................................ 179
OBTENER EL DÍGITO VERIFICADOR DE LA CÉDULA ..................................................................... 181
EJERCICIOS PROPUESTOS DIFERENTES Y NO RESUELTOS ........................................................... 183
GUÍA DE PROGRAMACIÓN DE C# ................................................................................................ 186
-Palabras clave de C#....................................................................................................................... 186
-Tipos de instrucciones.................................................................................................................... 191
-Instrucciones inalcanzables............................................................................................................ 192
Referencias...................................................................................................................................... 193

4
Ing. Patricio Medina
INVERTIR NÚMERO DE DOS
CIFRAS
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM, AUX, DEC,
UNI;
string linea;
Console.WriteLine
("INGRESE NÚMERO DE
DOS CIFRAS : " ) ;
l i n e a = Console.ReadLine();
NUM = i n t . P a r s e ( l i n e a ) ;
DEC = NUM/10;
UNI = NUM % 10;
AUX = (UNI * 10) + DEC;
Console.WriteLine("NÚMERO
INVERTIDO ES: " + AUX);
Console.WriteLine("Pulse
una Te c l a : " ) ;
4. GRABAR Console.ReadLine();
Y EJECUTAR
}
}
}
INVERTIR NÚMERO DE TRES
CIFRAS
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM, AUX, DEC,
UNI, CEN;
string linea;
Console.WriteLine
("INGRESE NÚMERO DE
TRES CIFRAS : " ) ;
l i n e a = Console.ReadLine(); 2
NUM = i n t . P a r s e ( l i n e a ) ;
Ing. Patricio Medina
CEN = NUM / 10 0;
NUM = NUM % 100;
DEC = NUM/10;
UNI = NUM % 10;
AUX = (UNI *
100) + (DEC*10)
+ CEN;
Console.WriteLin
e("NÚMERO
INVERTIDO ES: "
+ AUX);
Console.WriteLi
ne("Pulse una
Te c l a : " ) ;
Console.ReadLi
ne();
4. GRABAR
}
Y EJECUTAR
}
}

OPERACIONES
BÁSICAS
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
3
Ing. Patricio Medina
using System.Linq;
using System.Text;
namespace
ConsoleApplication
1
{
class Program
{
static
void
Main(stri
n g [ ] args)
{
int
NUM1,
NUM2,
RESUL;
string linea;
Console.Write("PRIMER NÚMERO : " ) ;
l i n e a = Console.ReadLine();
NUM1 = i n t . P a r s e ( l i n e a ) ;
Console.Write("SEGUNDO NÚMERO : " ) ;
l i n e a = Console.ReadLine();
NUM2 = i n t . P a r s e ( l i n e a ) ;
Consol e. Wr i t eLi ne( )
; RESUL = NUM1 +
NUM2;
Console.WriteLine("L
A SUMA ES { 0 } : " ,
RESUL);
RESUL = NUM1 -
NUM2;
Console.WriteLine("LA RESTA ES: { 0 } - { 1 } = { 2 } " , NUM1, NUM2, RESUL);
RESUL = NUM1 * NUM2;
Console.WriteLine("LA MULTIPLICACIÓN ES: " + RESUL);
RESUL = NUM1 / NUM2;
Console.WriteLine("LA DIVISIÓN ES: " + RESUL);
RESUL = NUM1 % NUM2;
Console.WriteLine("EL RESIDUO ES: " + RESUL);
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

4
Ing. Patricio Medina
COMPRA EN RESTAURANT
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
byte CANB, CANH, CANP;
double APAGAR;
string linea;
const double PRECIOB = 0 . 8 ;
const double PRECIOH = 2 ;
const double PRECIOP = 1 . 2 ;
Console.Write("CANTIDAD DE HAMBURGUESAS : " ) ; l i n e a = Console.ReadLine();
CANH = byte.Parse ( l i n e a ) ;
Console.Write("CANTIDAD DE PAPAS : " ) ; l i n e a = Console.ReadLine();
CANP = byte.Parse ( l i n e a ) ;
Console.Write("CANTIDAD DE BEBIDAS : " ) ; l i n e a = Console.ReadLine();
CANB = byte.Parse ( l i n e a ) ;
Console.WriteLine();
APAGAR = (CANH * PRECIOH) + (CANP * PRECIOP) + (CANB * PRECIOB);
Console.WriteLine("VALOR A PAGAR: " + APAGAR);
Console.Write("Pulse una Tecla:");Console.ReadLine();
}
}
}

5
Ing. Patricio Medina
4. GRABAR Y EJECUTAR

FUNCIONES BÁSICAS LIBRERÍA


MATH
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM1;
string linea;
long RESUL;
Console.Write("DIGITE UN NÚMERO : " ) ;
l i n e a = Console.ReadLine();
NUM1 = i n t . P a r s e ( l i n e a ) ;
RESUL = Math.Abs(NUM1);
Console.WriteLine("VALOR 6
ABSOLUTO : " + RESUL);
Ing. Patricio Medina
Console.WriteLine("POTENCIA : " + Math.Pow(NUM1, 3 ) ) ;
Console.WriteLine("RAIZ CUADRADA : " + Math.Sqrt(NUM1));
Console.WriteLine("SENO : " + Math.Sin(NUM1 * Math.PI / 1 8 0 ) ) ;
Console.WriteLine("COSENO : " + Math.Cos(NUM1 * Math.PI / 1 8 0 ) ) ;
Console.WriteLine("NÚMERO MÁXIMO : " + Math.Max(NUM1, 5 0 ) ) ;
Console.WriteLine("NÚMERO MÍNIMO : " + Math.Min(NUM1, 5 0 ) ) ;
Console.WriteLine("PARTE ENTERA : " + Math.Truncate(18.78));
Console.WriteLine("REDONDEO : " + Math.Round(18.78));
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

FORMATOS DE
SALIDA
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;

7
Ing. Patricio Medina
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ] args)
{
double BASE, ALTURA, RESUL;
string linea;
Console.Write("DIGITE LA BASE : " ) ; l i n e a = Console.ReadLine();
BASE = double.Parse ( l i n e a ) ;
Console.Write("DIGITE LA ALTURA:"); l i n e a = Console.ReadLine();
ALTURA= double.Parse ( l i n e a ) ;
RESUL = (BASE * ALTURA) / 2 ;
Console.WriteLine("AREA TRIANGULO : " + S t ri ng . Fo rmat ( " {0: ## ##. 00 }" , RESUL));
Console.WriteLine("AREA TRIANGULO : " + S t r i n g . F o r m a t ( " { 0 : c } " , RESUL));
Console.WriteLine("AREA TRIANGULO : " + S t r i n g . F o r m a t ( " { 0 : f } " , RESUL));
Console.WriteLine("AREA TRIANGULO : " + S t r i n g . F o r m a t ( " { 0 : g } " , RESUL));
Console.WriteLine();
Console.WriteLine("HOY ES: " + String.Format("Hoy es { 0 : F } " , DateTime.Now));
Console.WriteLine("HOY ES: " + String.Format("Hoy es {0:dddd}{0:dd/MM/yyy}",
DateTime.Now));
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

8
Ing. Patricio Medina
EJERCICIO PROPUESTO
Concepto:

El usuario debe ingresar dos números y el programa mostrará el resultado de la


operación (a+b)*(a-b)

1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ejercicio_propuesto_1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM1, NUM2;
double RESUL;
string linea;
Console.Write("NÚMERO 1 : " ) ; l i n e a = Console.ReadLine();
NUM1 = i n t . P a r s e ( l i n e a ) ;
Console.Write("NÚMERO 2 : " ) ; l i n e a = Console.ReadLine();
NUM2 = i n t . P a r s e ( l i n e a ) ;
RESUL = (NUM1 + NUM2) * (NUM1 - NUM2);
Console.WriteLine();
Console.WriteLine("El resultado es : " +RESUL ) ;
Console.ReadLine();
}
}
}
9
Ing. Patricio Medina
4. GRABAR Y EJECUTAR

MAYOR DE DOS
NÚMEROS
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM1, NUM2;
string linea;
10
Ing. Patricio Medina
Console.Write("NÚMERO 1 : " ) ; l i n e a = Console.ReadLine();
NUM1 = i n t . P a r s e ( l i n e a ) ;
Console.Write("NÚMERO 2 : " ) ; l i n e a = Console.ReadLine();
NUM2 = i n t . P a r s e ( l i n e a ) ;
i f ((NUM1 > NUM2))
{
Console.WriteLine("{
0} ES MAYOR QUE { 1 } " ,
NUM1, NUM2);
}
else
{
i f ((NUM1 == NUM2))
{
Console.WriteLi
ne("{0} ES IGUAL A
{ 1 } " , NUM1,
NUM2);
}
else
{
Console.WriteLi
ne("{0} ES MENOR
QUE { 1 } " , NUM1,
NUM2);
}
}
Console.WriteLine();
Console.WriteLine("OTRA MANERA");
s t r i n g RESUL;
i f (NUM1 > NUM2 )
{
RESUL = "MAYOR";
}
else
i f (NUM1 == NUM2 )
{
RESUL = "IGUAL";
}
else
{
RESUL = "MENOR";
}

Console.WriteLine("{0} ES { 1 } QUE
{ 2 } " , NUM1, RESUL, NUM2);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();

}
}
}
4. GRABAR Y EJECUTAR

11
Ing. Patricio Medina
MAYOR DE TRES
NÚMEROS
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
byte MAY, MEN, NUM1,
NUM2, NUM3;
string linea;
Console.Write("NÚMERO 1 : " ) ; l i n e a = Console.ReadLine();
NUM1 = b y t e . P a r s e ( l i n e a ) ;
Console.Write("NÚMERO 2 : " ) ; l i n e a = Console.ReadLine();
NUM2 = b y t e . P a r s e ( l i n e a ) ;
Console.Write("NÚMERO 3 : " ) ; l i n e a = Console.ReadLine();
NUM3 = b y t e>. PMAY))
i f ((NUM2 a r s e ( lMA
i nYe a=) ; NUM2;
i f >MEN
MAY = NUM1; = NUM1;
MAY)) MAY = NUM3;
((NUM3 i f > MEN)) MEN =
i((NUM2
f ((NUM3 < MEN)) NUM2;MEN = NUM3;
Console.WriteLine("MAYOR ES:" + MAY);
Console.WriteLine("MENOR ES:" + MEN);
Console.WriteLine("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}

12
Ing. Patricio Medina
4. GRABAR Y EJECUTAR

DESGLOSE DE
BILLETES
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t CAN, C100, C50, C20, C10, C5;
C100 = 0 ;
C50 = 0 ;
C20 = 0 ;
C10 = 0 ;
13
Ing. Patricio Medina
C5 = 0 ;
string linea;
Console.Write("DIGITE UNA CANTIDAD : " ) ; l i n e a = Console.ReadLine();
CAN = i n t . P a rs e ( l i n e a ) ;
i f ( (CAN >= 100) )
{
C100 = (CAN / 100);
CAN = CAN - (C100 * 100);
}
i f ( (CAN >= 50) )
{
C50 = (CAN / 5 0 ) ;
CAN = CAN - (C50 * 5 0 ) ;
}
i f ( (CAN >= 20) )
{
C20 = (CAN / 2 0 ) ;
CAN = CAN - (C20 * 2 0 ) ;
}
i f ( (CAN >= 10) )
{
C10 = (CAN / 1 0 ) ;
CAN = CAN - (C10 * 1 0 ) ;
}
i f ( (CAN >= 5 ) )
{
C5 = (CAN / 5 ) ;
CAN = CAN - (C5 * 5 ) ;
}
Console.WriteLine("BILLETES DE A 100: "+ C100);
Console.WriteLine("BILLETES DE A 50 : " + C50);
Console.WriteLine("BILLETES DE A 20 : " + C20);
Console.WriteLine("BILLETES DE A 10 : " + C10);
Console.WriteLine("BILLETES DE A 5 : " + C5);
Console.WriteLine("BILLETES DE A 1 : " + CAN);
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

14
Ing. Patricio Medina
BONO DEL EMPLEADO POR
HIJO
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication2
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
double SUELDO, ARECIBIR;
i n t NHIJO, BONO;
s t r i n g NOM, l i n e a ;
Console.Write("NOMBRE EMPLEADO : " ) ; NOM = Console.ReadLine();
Console.Write("SUELDO EMPLEADO : " ) ; l i n e a = Console.ReadLine();
SUELDO = double .P arse(linea);
Console.Write("NÚMERO DE HIJOS : " ) ; l i n e a = Console.ReadLine();
NHIJO = i n t . P a r s e ( l i n e a ) ;
i f (NHIJO >= 3) { BONO = NHIJO * 10; } else { BONO = NHIJO * 20; }
ARECIBIR = SUELDO + BONO;
Console.WriteLine("RECIBE : " + S t r i n g . F o r m a t ( " { 0 : c } " , ARECIBIR));
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

15
Ing. Patricio Medina
NÚMERO
INTERMEDIO
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM1, NUM2, NUM3;
string linea;
Console.Write("PRIMER NÚMERO : " ) ; l i n e a = Console.ReadLine();
NUM1 = i n t . P a r s e ( l i n e a ) ;
Console.Write("SEGUNDO NÚMERO : " ) ; l i n e a = Console.ReadLine();
NUM2 = i n t . P a r s e ( l i n e a ) ;
Console.Write("TERCER NÚMERO : " ) ; l i n e a = Console.ReadLine();
NUM3 = i n t . P a r s e ( l i n e a ) ;
Console.WriteLine();
Console.Write("EL INTERMEDIO ES: " ) ;
16
Ing. Patricio Medina
i f ((NUM1 > NUM2))
{
i f ((NUM1 < NUM3))
{
Console.WriteLine(NUM1);
}
else
{
i f ((NUM2 < NUM3))
{
Console.WriteLine(NUM3);
}
else
{
Console.WriteLine(NUM2);
}
}
}
else
{
i f ((NUM2 < NUM3))
{
Console.WriteLine(NUM2);
}
else
{
i f ((NUM1 < NUM3))
{
Console.WriteLine(NUM3);
}
else
{
Console.WriteLine(NUM1);
}
}
}
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

17
Ing. Patricio Medina
TARIFA
TELEFÓNICA
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t CANKV;
double TOT, COSKV;
COSKV = 0 ;
string linea;
Console.Write("Cantidad de K i l o v a t i o s : " ) ; l i n e a = Console.ReadLine();
CANKV = i n t . P a r s e ( l i n e a ) ;
i f ((CANKV <= 1000)) COSKV = 0. 1 4;
i f (((CANKV > 1000) & (CANKV <= 1800))) COSKV = 0. 1 2; i f
((CANKV > 1800)) COSKV = 0 . 8 ;
TOT = CANKV * COSKV;
Console.WriteLine("A PAGAR: " + TOT);
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}

18
Ing. Patricio Medina
4. GRABAR Y EJECUTAR

TRIÁNGULOS
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t LADO1, LADO2,
LADO3;
string linea;
Console.Write("DIGITE LADO 1 : " ) ; l i n e a = Console.ReadLine();
LADO1 = i n t . P a r s e ( l i n e a ) ;
Console.Write("DIGITE LADO 2 : " ) ; l i n e a = Console.ReadLine();
LADO2 = i n t . P a r s e ( l i n e a ) ;
Console.Write("DIGITE LADO 3 : " ) ; l i n e a = Console.ReadLine(); 19
LADO3 = i n t . P a r s e ( l i n e a ) ;
Ing. Patricio Medina
i f ((LADO1 == LADO2) & (LADO2 == LADO3))
{
Console.WriteLine("TRIÁNGULO EQUILÁTERO. TODOS IGUALES");
}
else
{
i f ((LADO1 ! = LADO2) & (LADO1 ! = LADO3) & (LADO2 ! =
LADO3))
{
Console.WriteLine("TRIÁNGULO ESCALENO. NINGUNO IGUAL");
}
else
{
Console.WriteLine("TRIÁNGULO ISÓSCELES. DOS IGUALES");
}
}
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

EJERCICIO PROPUESTO
Concepto:

Crear un programa que pida al usuario su nombre, y le diga "Hola" si se llama


"David", o bien le diga "No te conozco" si teclea otro nombre.

1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

20
Ing. Patricio Medina
3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ejercicio_Propuesto_2
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
s t r i n g NOMBRE;
Console.Write("Ingrese su nombre : " ) ; NOMBRE = Console.ReadLine();
i f (NOMBRE == "Davi d" )
{
Console.WriteLine();
Consol e. Wr i t eLi ne( " HOLA"
);
}
else
{
Console.WriteLine();
Console.WriteLine("NO TE CONOZCO");
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

21
Ing. Patricio Medina
DÍA DE LA
SEMANA
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Dias_de_la_Semana
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t num;
string linea;
Console.WriteLine();
Console.WriteLine("DIAS DE LA SEMANA");
Console.WriteLine();
Console.Write("Ingrese un numero de l 1 a l 7 : " ) ;
l i n e a = Console.ReadLine();
num = i n t . P a r s e ( l i n e a ) ; 22
Ing. Patricio Medina
switch (num)
{
case 1 :
Console.WriteLine();
Console.WriteLine("El numero que ingreso corresponde a l di a
DOMINGO");
br eak;
case 2 :
C
onsol
e.Writ
eLine(
);
Console.WriteLine("El numero que ingreso corresponde a l di a
LUNES"); break;
case 3 :
Console.WriteLine();
Console.WriteLine("El numero que ingreso corresponde a l di a
MARTES"); break;
case 4 :
Console.WriteLine();
Console.WriteLine("El numero que ingreso corresponde a l di a
MIERCOLES");
br eak;
case 5 :
C
onsol
e.Writ
eLine(
);
Console.WriteLine("El numero que ingreso corresponde a l di a
JUEVES"); break;
case 6 :
Console.WriteLine();
Console.WriteLine("El numero que ingreso corresponde a l di a
VIERNES");
br eak;
case 7 :
C
onsol
e.Writ
eLine(
);
Console.WriteLine("El numero que ingreso corresponde a l di a
SABADO"); break;
default:
Console.WriteLine();
Console.WriteLine("El numero que ingreso esta fuera de
ra n g o " ); break;
}
Console.ReadKey();
4. GRABAR
} Y EJECUTAR
}
}

23
Ing. Patricio Medina
ESTADO CIVIL
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
char ECIVIL;
string linea;
Console.Write
("DIGITE
C,S,V,D : " ) ;
linea =
Console.Read
Line();
ECIVIL = c h a r . P a rs e ( l i n e a );
switch (ECIVIL) 24
{
Ing. Patricio Medina
case ' C ' : ; Console.WriteLine("CASADO");
break;
case ' S ' : ; Console.WriteLine("SOLTERO");
break;
case ' V ' : ; Console.WriteLine("VIUDO");
break;
case ' D ' : ; Console.WriteLine("DIVORCIADO");
break;
default:
Console.WriteLine("NO EXISTE");
break;
}
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

CALIFICACIÓN
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
25
Ing. Patricio Medina
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NOTA;
string linea;
Console.Write
("DIGITE
CALIFICACIÓ
N:");linea =
Console.Read
Line();
NOTA= byte.Parse ( l i n e a ) ;
switch(NOTA)
{
case 19:
case 20: ; Console.WriteLine("SOBRESALIENTE");
break;
case 16:
case 17:
case 18:;Console.WriteLine("MUY BUENA");
break;
case 14:
case 1 5 : ; Console.WriteLine("BUENA");
break;
case 12:
case 13:;Console.WriteLine("REGULAR");
break;
case 1 :
case 2 :
case 3 :
case 4 :
case 5 :
case 6 :
case 7 :
case 8 :
case 9 :
case 10:
case 11:
Console.WriteLine("INSUFICIENTE");
break;
default:
Console.WriteLine("FUERA DE RANGO");
break;
}
Console.Write("Pulse una
Tecla:");Console.ReadLine();
4. GRABAR
} Y EJECUTAR
}
}

26
Ing. Patricio Medina
EJERCICIO PROPUESTO
Concepto:

Crear un programa que lea una letra tecleada por el usuario y diga si se trata de una
vocal, una cifra numérica o una consonante (pista: habrá que usar un dato de tipo
"char").

1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ejercicio_Propuesto_3
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
char TECLA;
27
Ing. Patricio Medina
string linea;
Console.Write("DIGITE UNA SOLA TECLA");
Console.WriteLine();
l i n e a = Console.ReadLine();
TECLA = c h a r . P a rs e ( l i n e a );
switch (TECLA)
{
case ' 1 ' :
case ' 2 ' :
case ' 3 ' :
case ' 4 ' :
case ' 5 ' :
case ' 6 ' :
case ' 7 ' :
case ' 8 ' :
case ' 9 ' : ; Console.WriteLine("ES UNA CIFRA NUMERICA");
break;
case ' a ' :
case ' e ' :
case ' i ' :
case ' o ' :
case ' u ' : ; Console.WriteLine("ES UNA VOCAL");
break;
default:
Console.WriteLine("ES UNA CONSONANTE");
break;
}
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();

}
}
}

4. GRABAR Y EJECUTAR

28
Ing. Patricio Medina
TABLA DE
MULTIPLICAR
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TABLA_DE_MULTIPLICAR
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
byte NUM, I ;
i n t RESUL;
string linea;
Console.Write("DIGITE NÚMERO:"); l i n e a = Console.ReadLine();
NUM = b y t e . P a r s e ( l i n e a ) ;
f o r ( I = 1 ; I <= 12; I ++)
{
RESUL = NUM * I ;
Console.WriteLine("{0} * { 1 } = { 2 } " , NUM, I , RESUL);
}
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}

29
Ing. Patricio Medina
4. GRABAR Y EJECUTAR

PRESUPUESTO ANUAL EN AREAS


HOSPITAL
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
PRESUPUESTO_ANUAL_EN_AREAS_HOSPIT
AL
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
double CANP, TOT, PORC;
s t r i n g AREA,linea;
30
Ing. Patricio Medina
byte CAN, I ;
Console.Write("CUANTOS CALCULOS: " ) ; l i n e a = Console.ReadLine();
CAN = b y t e . P a r s e ( l i n e a ) ;
Console.Write("DIGITE TOTAL DEL PRESUPUESTO: " ) ; l i n e a =
Console.ReadLine();
CANP = double .P arse(linea);
f o r ( I = 1 ; I <= CAN; I ++)
{
Console.Write("DIGITE ÁREA: " ) ; AREA = Console.ReadLine();
switch (AREA.ToUpper())
{
case "GINECOLOGIA": ; PORC = 40;
break;
case "TRAUMATOLOGIA": ; PORC = 30;
break;
case "PEDIATRIA": ; PORC = 30;
br eak;
default:
PO
RC =
0;
br
eak;
}
TOT = (CANP
* PORC) / 100;
Console.Wr
iteLine(AREA +
" RECIBE " +
String.Format
("{0:C}",
TOT));
}
Console.Write(
"Pulse una
Te c l a : " ) ;
Console.ReadLine(
);
}
}
}
4. GRABAR Y
EJECUTAR

31
Ing. Patricio Medina
SUMA DE N NÚMEROS PARESE
IMPARES
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
SUMA_DE_N_NÚMEROS_PARES_E_IMPARES
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
byte NUM, I ;
i n t SUMP = 0 ;
i n t SUMI = 0 ;
string linea;
Console.Write("NÚMERO MÁXIMO: " ) ; l i n e a = Console.ReadLine();
NUM = b y t e . P a r s e ( l i n e a ) ;
f o r ( I = 1 ; I <= NUM; I += 2 )
{
SUMP = SUMP + I ;
}
f o r ( I = 2 ; I <= NUM; I += 2 )
{
SUMI = SUMI + I ;
}
Console.WriteLine("TOTAL EN PARES : " + SUMP);
Console.WriteLine("TOTAL EN IMPARES : " + SUMI);
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR 32
Ing. Patricio Medina
TABLAS DE
MULTIPLICAR
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace TABLAS_DE_MULTIPLICAR
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM, RESUL, T, I ;
string linea;
Console.Write("CUANTAS TABLAS: " ) ; l i n e a = Console.ReadLine();
NUM = i n t . P a r s e ( l i n e a ) ;
f o r (T = 1 ; T <= NUM; T++)
{
f o r ( I = 10; I >= 1 ; I - - )
{
RESUL = T * I ; 33
Ing. Patricio Medina
Console.WriteLine("{0} * { 1 } = { 2 } " , T, I , RESUL);
}
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}
}

4. GRABAR Y EJECUTAR

34
Ing. Patricio Medina
SUMA DE N
NÚMEROS
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SUMA_DE_N_NÚMEROS
{
class Program
{
s t a t i c void
M a i n ( s t r i n g [ ] args)
{
byte CAN, K;
i n t NUM;
i n t SUM = 0 ;
string linea;
Console.Writ
e("LÍMITE:");
linea =
Console.Read
Line();
CAN = b y t e . P a r s e ( l i n e a ) ;
f o r (K = 1 ; K <= CAN; K++)
{
Console.Write("DIGITE UN NÚMERO:"); l i n e a = Console.ReadLine();
NUM=int.Parse ( l i n e a ) ;
SUM += NUM;
}
Console.WriteLine("SUMA TOTAL ES : " + SUM);
Console.WriteLine("MEDIA ARITMÉTICA: " + SUM / CAN);
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}
35
Ing. Patricio Medina
4. GRABAR Y EJECUTAR

MAYOR Y MENOR DE N
NÚMEROS
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
byte CAN, K;
i n t MAY, MEN, NUM;
36
Ing. Patricio Medina
string linea;
Console.Write("LÍMITE:"); l i n e a = Console.ReadLine();
CAN = b y t e . P a r s e ( l i n e a ) ;
Console.Write("DIGITE UN NÚMERO:"); l i n e a = Console.ReadLine();
MAY = i n t . P a r s e ( l i n e a ) ;
MEN = MAY;
f o r (K = 2 ; K <= CAN; K++)
{
Console.Write("DIGITE UN NÚMERO:"); l i n e a = Console.ReadLine();
NUM = i n t . P a r s e ( l i n e a ) ;
i f (NUM > MAY) MAY = NUM; i f
(NUM < MEN) MEN = NUM;
}
Console.WriteLine("EL MAYOR ES : " + MAY);
Console.WriteLine("EL MENOR ES : " + MEN);
Console.WriteLine("DIFERENCIA ES : " + (MAY - MEN));
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

37
Ing. Patricio Medina
SERIE DE
FIBONACCI
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SERIE_DE_FIBONACCI
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
byte CAN, K;
i n t A, B, C;
string linea;
Console.Write("CUANTOS NÚMEROS: " ) ; l i n e a = Console.ReadLine();
CAN = b y t e . P a r s e ( l i n e a ) ;
A = 1;B = 1 ;
Console.Write(A + " " + B + " " ) ;
f o r ( K = 3 ; K <= CAN; K++){
C = A + B;
Console.Write(C + " " ) ;
//INTERCAMBIO DE VALORES
A = B;
B = C;
}
Console.WriteLine();
Console.Write("Pulse una
Te c l a : " ) ;
Console.ReadLine();
}
}
}
38
Ing. Patricio Medina
4. GRABAR Y EJECUTAR

CALIFICACIONES DE UN GRUPO DE
ESTUDIANTES
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
CALIFICACIONES_DE_UN_GRUPO_DE_EST
UDIANTES
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
byte CAN, K;
double NOTA1, NOTA2,
PROM, SUM;
s t r i n g NOM, l i n e a ;
Console.Write("CUANTOS ESTUDIANTES: " ) ; l i n e a = Console.ReadLine();
CAN = b y t e . P a r s e ( l i n e a ) ;
SUM = 0 ;
39
Ing. Patricio Medina
f o r (K = 1 ; K <= CAN; K++)
{
Console.Write("NOMBRE: " ) ; NOM = Console.ReadLine();
Console.Write("NOTA 1 : " ) ; l i n e a = Console.ReadLine();
NOTA1 = double .P arse(linea);
Console.Write("NOTA 2 : " ) ; l i n e a = Console.ReadLine();
NOTA2 = double .P arse(linea);
PROM = (NOTA1 + NOTA2) / 2 ;
Console.WriteLine("PROMEDIO: " + PROM);
SUM += PROM;
}
Console.WriteLine();
Console.WriteLine("SUMA TOTAL ES : " + SUM);
Console.WriteLine("MEDIA ARITMÉTICA: " + SUM / CAN);
Console.WriteLine("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

40
Ing. Patricio Medina
NÚMEROS ALEATORIOS Y CARACTERES
ASCII
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
NÚMEROS_ALEATORIOS_Y_CARACTERES_
ASCII
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
byte CAN, K;
i n t NUM;
string linea;
Console.Write("CUANTOS NÚMEROS: " ) ; l i n e a = Console.ReadLine();
CAN = b y t e . P a r s e ( l i n e a ) ;
//INICIALIZA EL GENERADOR DE ALEATORIOS
Random ran = new Random();
f o r ( K = 1 ; K <= CAN; K++){
NUM =
Convert.ToInt32(ran.Next(1
00));
Console.WriteLine("GENERÓ EL: " + NUM);
i f ( ((NUM > 0 ) & (NUM < 256)) ) {
Console.WriteLine("EL CÓDIGO DEL " + NUM +
" ES " +
Convert.ToString((char)NUM));
}
}
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
41
Ing. Patricio
} Medina
}
4. GRABAR Y EJECUTAR

FUNCIONES DE
CADENA
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FUNCIONES_DE_CADENA
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
s t r i n g NOM;
byte K;
Console.Wri 42
te("DIGITE
Ing. Patricio Medina
SU NOMBRE :
" ) ; NOM =
Console.Re
adLine();
Console.WriteLine("LONGITUD : " + NOM.Length);
Console.WriteLine("ESTA DENTRO : " + NOM.Contains("ARIEL"));
Console.WriteLine("REEMPLAZO VOCAL A: " + NOM.Replace("A", " X " ) ) ;
Console.WriteLine("EN MINUSCULAS : " + NOM.ToLower());
Console.WriteLine("EN MAYÚSCULAS : " + NOM.ToUpper());
Console.WriteLine("REMOVER 4 LETRAS : " + NOM.Remove(3, 4 ) ) ;
Console.WriteLine("EXTRAER 4 LETRAS : " + NOM.Substring(3, 4 ) ) ;
Console.WriteLine("IZQUIERDA 4 LETRAS : " + Left(NOM, 4 ) ) ;
Console.WriteLine("DERECHA 4 LETRAS : " + Right(NOM, 4 ) ) ;
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
Console.WriteLine();
Console.WriteLine("DESDE LA IZQUIERDA");
f o r (K = 1 ; K <= NOM.Length; K++)
{
Console.WriteLine(Left(NOM, K ) ) ;
}
Console.WriteLine();
Console.WriteLine("DESDE LA DERECHA");
f o r (K = 1 ; K <= NOM.Length; K++)
{
Console.WriteLine(Right(NOM, K ) ) ;
}
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
p u b l i c s t a t i c s t r i n g L e f t ( s t r i n g param, i n t
length)
{
s t r i n g r e s u l t = param.Substring(0, l e n g t h ) ;
return r e s u l t ;
}
p u b l i c s t a t i c s t r i n g R i g h t ( s t r i n g param, i n t
length)
{
i n t value = param.Length - l e n g t h ;
s t r i n g r e s u l t = param.Substring(value, l e n g t h ) ;
return r e s u l t ;
}
}
}
4. GRABAR Y EJECUTAR

43
Ing. Patricio Medina
SIMULACIÓN DE UN RELOJ
DIGITAL
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
SIMULACIÓN_DE_UN_RELOJ_DIGITAL
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
44
Ing. Patricio Medina
{
byte H, M, S;
Console.SetCursorPosition(15, 2 ) ;
Console.Write("SIMULACIÓN DE UN RELOJ DIGITAL");
f o r (H = 0 ; H <= 24; H++)
{
f o r (M = 0 ; M <= 59; M++)
{
f o r (S = 0 ; S <= 59; S++)
{
Console.SetCursorPosition(20, 1 0 ) ;
Console.Write("{0} : { 1 } : { 2 } " , H, M, S ) ;
}
}
}
Console.SetCursorPosition(25, 1 5 ) ;
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

45
Ing. Patricio Medina
CANTIDAD DE VOCALES
CERRADAS
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace CANTIDAD_DE_VOCALES_CERRADAS
{
class CANTIDAD_DE_VOCALES_CERRADAS
{
s t a t i c void M a i n ( s t r i n g [ ] args)
{
s t r i n g NOM;
i n t K, SUM;
s t r i n g LE;
Console.Write("DIGITE UNA FRASE : " ) ; NOM = Console.ReadLine();
SUM = 0 ;
NOM = NOM.ToUpper();
Console.Write(NOM);
f o r (K = 1 ; K < NOM.Length; K++)
{
LE = Mid(NOM, K, 1 ) ;
i f (LE.Contains("U") | | L E . C o n t a i n s ( " I " ))
{
SUM = SUM + 1 ;
}
}
Console.WriteLine("EXISTEN { 0 } VOCALES CERRADAS", SUM);
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
p u b l i c s t a t i c s t r i n g M i d ( s t r i n g param, i n t s t a r t I n d e x , i n t l e n g t h )
{
s t r i n g r e s u l t = param.Substring(startIndex, l e n g t h ) ;
return r e s u l t ;
46
Ing. Patricio Medina
}
p u b l i c s t a t i c s t r i n g M i d ( s t r i n g param, i n t s t a r t I n d e x )
{
s t r i n g r e s u l t = param.Substring(startIndex);
return r e s u l t ;
}
}
}
4. GRABAR Y EJECUTAR

ESTADISTICA POR
VOCAL
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{

class Program
{
47
Ing. Patricio Medina
p u b l i c s t a t i c s t r i n g M i d ( s t r i n g param, i n t s t a r t I n d e x , i n t l e n g t h )
{
s t r i n g r e s u l t = param.Substring(startIndex, l e n g t h ) ;
return r e s u l t ;
}
s t a t i c void M a i n ( s t r i n g [ ] args)
{
s t r i n g NOM ;
i n t K= 0;
i n t A= 0 ;
i n t E= 0;
int

I = 0; i n t O
= 0; i n t U =
0; string

LE ;
Console.Write("DIGITE UNA FRASE : " ) ;
NOM = Console.ReadLine();
A = 0;
E = 0;
I = 0;
O = 0;
U = 0;
f o r (K = 1 ; K < NOM.Length; K++)
{
NOM = NOM.ToUpper();
LE = Mid(NOM, K, 1 ) ;
switch (LE)
{
case " A " :
A= A+ 1 ;
br eak;
case " E " :
E
= E+
1;
br eak;
case " I " :
I
=I +
1;
br eak;
case " O" :
O
= O+
1;
br eak;
case " U " :
U
=U+
1;
br
eak;
}
}
Console.WriteLine("EXISTEN { 0 } VOCALES A " ,
A ) ; Console.WriteLine("EXISTEN { 0 } VOCALES E " ,
E ) ; Console.WriteLine("EXISTEN { 0 } VOCALES I " , 48
Ing. Patricio Medina
I ) ; Console.WriteLine("EXISTEN { 0 } VOCALES O",
O); Console.WriteLine("EXISTEN { 0 } VOCALES U" ,
U); Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
FACTORIAL DE UN
NÚMERO
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace FACTORIAL_DE_UN_NÚMERO
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
byte NUM, K;
long RESUL = 1 ;
string linea;
Console.Write("DIGITE UN NÚMERO: " ) ; l i n e a = Console.ReadLine();
NUM = b y t e . P a r s e ( l i n e a ) ;
f o r (K = 2 ; K <= NUM; K++)
{
RESUL = RESUL * K;
}
49
Ing. Patricio Medina
Console.WriteLine("EL FACTORIAL ES: " + RESUL);
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

SERIE DE UN
NÚMERO
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

50
Ing. Patricio Medina
namespace SERIE_DE_UN_NÚMERO
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ] args)
{
byte NUM, K, F;
long FAC;
double RESUL =
0;
string linea;
Console.Write("DIGITE UN NÚMERO: " ) ; l i n e a = Console.ReadLine();
NUM = b y t e . P a r s e ( l i n e a ) ;
f o r (K = 1 ; K <= NUM; K++)
{
FAC = 1 ;
f o r (F = 1 ; F <= K; F++)
{
FAC = FAC * F;
}
RESUL = RESUL + (K / FAC);
}
Console.WriteLine("RESULTADO DE LA SERIE ES: " + RESUL);
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

51
Ing. Patricio Medina
SUCESIÓN DE N
CUADROS
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace SUCESIÓN_DE_N_CUADROS
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t CAN, F, C, T, F I ,
FF, C I , CF; l i n e a = Console.ReadLine();
string linea;
Console.Write("DIGITE
UN NÚMERO MÁX=10: " ) ;
CAN = b y t e . P a r s e ( l i n e a ) ;
FI = 2 ; FF = 22;
CI = 2 ; CF = 77;
f o r (T = 1 ; T <= CAN; T++)
{ Console.SetCursorPosition(F, FF); Console.Write("X");
f o r (F = C I ; F <= CF;
Console.SetCursorPosition(F, FI); Console.Write("X");
}F++)
f{ o r (C = F I ; C <= FF; C++)
{
Console.SetCursorPosition(CI, C); Console.Write("X");
Console.SetCursorPosition(CF, C); Console.Write("X");
}
FI = FI + 1 ; FF = FF - 1 ; CI
= CI + 1 ; CF = CF - 1 ;
}
Console.WriteLine();
52
Ing. Patricio Medina
Console.SetCursorPosition(25, 2 4 ) ; Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

MOVIMIENTO DE UNA
FRASE
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO

53
Ing. Patricio Medina
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MOVIMIENTO_DE_UNA_FRASE
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
s t r i n g NOM;
byte K;
Console.Write("SU NOMBRE ES: ");NOM = Console.ReadLine();
f o r ( K = 1 ; K <= 70; K++){
Console.SetCursorPosition(K, 1 2 ) ;
Console.Write(" " + NOM);
//REALIZAMOS UNA PAUSA;
System.Threading.Thread.Sleep(10
0);
}
Console.WriteLine();
Console.Write("Pulse una
Tecla:");Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

54
Ing. Patricio Medina
MOVIMIENTO CARÁCTERPORCARÁCTER HORIZONTAL
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public s t a t i c s t r i n g
M i d ( s t r i n g param, i n t
startIndex, i n t length)
{
s t r i n g r e s u l t = param.Substring(startIndex, l e n g t h ) ;
return r e s u l t ;
}
s t a t i c void M a i n ( s t r i n g [ ] args) 55
Ing. Patricio Medina
{
s t r i n g NOM ;
string
CAR ; i n t K
= 0; i n t P=
0 ; i n t CI =
0 ; i n t CF =
0;
Console.Write("SU NOMBRE ES: " ) ;
NOM = Console.ReadLine();
Console.SetCursorPosition(1, 1 2 ) ;
Console.Write(NOM);
CI = NOM.Length;
CF = 70;
NOM =
NOM.ToUpper();
f o r (P =
NOM.Length; P >=
1; P--)
{
CAR = Mid(NOM, P-1, 1 ) ;
f o r (K = C I ; K <=CF; K++)
{
Console.SetCursorPosition(K, 1 2 ) ;
Console.Write(" " + CAR);
/ / REALIZAMOS UNA PAUSA
System.Threading.Thread.Sleep(50)
;
}
CF = CF - 1 ;
CI = CI - 1 ;
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadKey ( ) ;
}
}
}4. GRABAR Y EJECUTAR

56
Ing. Patricio Medina
MOVIMIENTO CARÁCTERPORCARÁCTER VERTICAL
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
public s t a t i c s t r i n g
M i d ( s t r i n g param, i n t
startIndex, i n t length)
{
s t r i n g r e s u l t = param.Substring(startIndex, l e n g t h ) ;
return r e s u l t ;
}
s t a t i c void M a i n ( s t r i n g [ ] args)
{
s t r i n g NOM ;
string
CAR ; i n t K
= 0; i n t P=
0 ; i n t CI =
0;
Console.Write("SU NOMBRE ES: " ) ;
NOM = Console.ReadLine();
Console.Clear();
Console.SetCursorPosition(25, 1 ) ;
Consol e. Wr i t e( NO
M) ; CI = 25;
NOM = NOM.ToUpper();
f o r (P = 1 ; P <=
NOM.Length; P++) 57
{
Ing. Patricio Medina CAR = Mid(NOM, P-1, 1 ) ;
f o r (K = 1 ; K <= 22; K++)
{
Console.SetCursorPosition(CI, K ) ;
Console.Write(CAR);
/ / REALIZAMOS UNA PAUSA
System.Threading.Thread.Sleep(50);
Console.SetCursorPosition(CI, K ) ;
Console.Write(" " ) ;
}
Console.SetCursorPosition(CI, K ) ;
Console.Write(CAR);
CI = CI + 1 ;
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadKey();
}
}
}

4. GRABAR Y EJECUTAR

58
Ing. Patricio Medina
EJERCICIO PROPUESTO
Concepto:

Crear un programa que muestre las letras de la Z (mayúscula) a la A (mayúscula,


descendiendo).

1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace EJERCICIO_PROPUESTO_4
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
int i ;
Console.Write("ABECED
ARIO DESCENDENTE");
Console.WriteLine();
f o r ( i = 90; i >= 65 ;
i--)
{
Console.WriteLine
("LETRA: " +
C o n v e r t . To S t r i n g
((char)i));
}

Console.Write("Pulse
59
una Te c l a : " ) ;
Ing. Patricio Medina
Console.ReadLine();

}
}
}
4. GRABAR Y EJECUTAR

TABLA DE MULTIPLICAR CON


WHILE
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
60
Ing. Patricio Medina
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
TABLA_DE_MULTIPLICAR_CON_WHILE
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM, I , RESUL;
string linea;
Console.Write("DIGITE NÚMERO:"); l i n e a = Console.ReadLine();
NUM = i n t . P a r s e ( l i n e a ) ;
I = 1;
while ( ( I <= 12 ))
{
RESUL = NUM * I ;
Console.WriteLine("{0} * { 1 } = { 2 } " , NUM, I , RESUL); I
= I + 1;
}
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

61
Ing. Patricio Medina
TABLAS DE MULTIPLICAR CON
WHILE
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
TABLAS_DE_MULTIPLICAR_CON_WHILE
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM, RESUL, T, I ;
string linea;
Console.Write("CUANTAS TABLAS: " ) ; l i n e a = Console.ReadLine();
NUM= i n t . P a rs e ( l i n e a ) ;
T = 1;
while ( ( T <= NUM))
{
I = 10;
while ( ! ( ( I < 1 ) ) )
{
RESUL = T * I ;
Console.WriteLine("{0} * { 1 } = { 2 } " , T, I , RESUL); I
= I - 1;
}
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
T = T + 1;
}
}
}
}
4. GRABAR Y EJECUTAR 62
Ing. Patricio Medina
COMPROBAR SI ES NÚMERO
PRIMO
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
Comprobar_si_es_Numero_Primo
{
class Program
{
63
Ing. Patricio Medina
s t a t i c void M a i n ( s t r i n g [ ] args)
{
i n t n , x , sw, r e s i ;
string linea;
x = 2;
sw = 0 ;
Console.WriteLine("NUMERO PRIMO");
Console.WriteLine();
Console.Write("Ingrese e l numero:");
l i n e a = Console.ReadLine();
n = int.Parse(linea);
while ( x < n && sw == 0 )
{
resi = n % x;
i f ( r e s i == 0 )
{
sw = 1 ;
}
else
{
x = x + 1;
}
}
i f (sw == 0 )
{
Console.WriteLine();
Console.WriteLine("El numero es PRIMO");
}
else
{
Console.WriteLine();
Console.WriteLine("El numero no es
PRIMO");
}
Console.ReadKey();
}
}
}
4. GRABAR Y EJECUTAR

64
Ing. Patricio Medina
FACTORES PRIMOS DE UN
NÚMERO
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
FACTORES_PRIMOS_DE_UN_NÚMERO
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM, RESI, K;
string linea;
Console.Write("NÚMERO: " ) ; l i n e a = Console.ReadLine();
NUM= i n t . P a r s e ( l i n e a ) ;
K= 2;
while ((NUM ! = 1 ) )
{
RESI = NUM % K;
i f ((RESI == 0 ) )
{
Consol e. Wr i t eLi ne( K)
; NUM = NUM / K;
}
else
{
K= K+ 1;
}
}
Console.Write("Pulse una
Te c l a : " ) ; Console.ReadLine();
} 65
}
Ing.
}
Patricio Medina
4. GRABAR Y EJECUTAR

GENERAR N NÚMEROS
PRIMOS
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
GENERAR_N_NÚMEROS_PRIMOS
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM, RESI, K, SW,
CAN, X;
string linea;
Console.Write("CUANTOS NÚMEROS: " ) ; l i n e a = Console.ReadLine();
CAN = i n t . P a r s e ( l i n e a ) ;
NUM = 1;X = 0 ;
w h i l e ( (X < CAN))
{ K = 2;SW = 0 ; 66
Ing. Patricio Medina
w h i l e ( ((K < NUM) &
(SW == 0 ) ) ) {
RESI = NUM % K;
i f ( (RESI == 0) )
{ SW= 1 ;
}else{
K= K+ 1;
}
}
i f ( (SW == 0) ) {
Console.Write(NUM + " " ) ;
X= X+ 1;
}
NUM = NUM + 1 ;
}
Console.WriteLine();
Console.Write("Pulse una
Tecla:");Console.ReadLin
e();
}
}
}
4. GRABAR Y EJECUTAR

67
Ing. Patricio Medina
EJERCICIO PROPUESTOS
Concepto:

Crear un programa calcule cuantas cifras tiene un número entero positivo (pista: se
puede hacer dividiendo varias veces entre 10).

1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ejercicio_Propuesto_5
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM, I , Z, cont=0;
string linea;
Console.Write("DIGITE
NÚMERO:"); l i n e a =
Console.ReadLine();
NUM = i n t . P a r s e ( l i n e a ) ;
Z = linea.Length;
I = Z;
while ( ( I >= 1 ) )
{
I--;
cont++;
}
Console.WriteLine();
Console.WriteLine("El numero ingresado t i e n e " + cont + " d i g i t o s " ) ; 68
Ing. Patricio Medina
Console.Write("Pulse una Te c l a : " ) ; Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

VERIFICACIÓN DE UNA CLAVE 3 OPORTUNIDADES


1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace
VERIFICACIÓN_DE_UNA_CLAVE_3_OPORT
UNIDADES
{
class Program
{
69
s t a t i c void M a i n ( s t r i n g [ ]
Ing. Patricio
args)Medina
{
byte K, SW;
s t r i n g CLAVE;
SW= 0 ; K = 0 ;
do
{
Console.Write("DIGITE CLAVE: " ) ; CLAVE = Console.ReadLine();
i f ((CLAVE.ToUpper() == "ARIEL"))
{
SW= 1 ;
}
else
{
K++;
}
} while ( ( ( K < 3) & (SW == 0 ) ) ) ;
i f (SW == 1 )
{
Console.WriteLine("BIENVENID
O " + CLAVE);
}
else
{
Console.WriteLine("OPORTUNIDA
DES TERMINADAS");
}
Console.Write("Pulse una
Te c l a : " ) ; Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

70
Ing. Patricio Medina
GENERAR UN NÚMERO ALEATORIO ENTRE 10 Y
30
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM;
s t r i n g OP;
Random ran = new Random();
do{
do{
NUM =
Convert.ToInt32(ran.Next(1
00));
} w h i l e ( ! ( ((NUM >= 10) &
(NUM <= 3 0 ) ) ) ) ;
Console.WriteLine("SE
GENERO EL " + NUM);
Console.Write("GENERA OTRO NÚMERO S/N:");OP = Console.ReadLine();
OP = OP.ToUpper();
} w h i l e ( OP == " S " ) ;
Console.Write("Pulse una Tecla:");Console.ReadLine();
}
}
}

71
Ing. Patricio Medina
4. GRABAR Y EJECUTAR

JUEGO ADIVINA UN
NÚMERO
1. Abrir un nuevo Proyecto

2. Seleccione Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace JUEGO_ADIVINA_UN_NÚMERO
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
const i n t OPOR = 4 ;
i n t NUM, ADI;
byte I , SW;
string linea;
//GENERO EL 72
NÚMERO ENTRE 1
Ing. Patricio Medina
AL 20;
Random ran = new Random();
do{
NUM =
Convert.ToInt32(ran.Next(1
00));
} w h i l e ( ! ( ((NUM >= 1) & (NUM
<= 2 0 ) ) ) ) ;
//PROCESO;
I = 1;SW = 0 ;
do{
Console.Write("PIENSA QUÉ NÚMERO SERÁ:"); l i n e a = Console.ReadLine();
ADI = i n t . P a r s e ( l i n e a ) ;
i f ( (ADI == NUM) ) {
Console.WriteLine("ADIVINASTE ERES GENIAL");
SW= 1 ;
}
else{

i f ( (ADI > NUM) ) {


Console.WriteLine("TE PASASTE");

else{
Console.WriteLine("ESTÁS BAJO");

}
}
I+
+;
} w h i l e ( ( ( I <= OPOR) & (SW ==
0 ) ) ) ; i f ( (SW == 0) ) {
Console.Write("EL NÚMERO
FUE: " + NUM);
}
Console.WriteLine();
Console.Write("Pulse una
Te c l a : " ) ; Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

73
Ing. Patricio Medina
CONTROL DE UNA
FACTURA
1. Abrir un nuevo Proyecto

2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
s t r i n g PROD ;
i n t CAN = 0 ;
int

FI = 0 ; double
PRE = 0 ; double
TOT = 0 ;
double PAGA = 0 ;
char OP ;
string linea;
FI = 6 ;
PAGA = 0 ;
Console.SetCursorPosition(5, 4 ) ;
Console.Write("PRODUCTO CANTIDAD PRECIO TOTAL");
do
{
Console.SetCursorPosition(5, F I ) ;
PROD = Console.ReadLine();
Console.SetCursorPosition(17, F I ) ;
l i n e a = Console.ReadLine();
CAN = i n t . P a r s e ( l i n e a ) ;
Console.SetCursorPosition(27, F I ) ;
l i n e a = Console.ReadLine();
PRE = i n t . P a r s e ( l i n e a ) ;
TOT = CAN * PRE; 74
Ing. Patricio Medina Console.SetCursorPosition(33, F I ) ;
Console.Write(TOT);
PAGA = PAGA + TOT; FI
= FI + 1 ;
Console.SetCursorPosition(30, 2 3 ) ;
Console.Write("OTRO PRODUCTO S / N : " ) ;
l i n e a = Console.ReadLine();
OP = char.Parse(linea.ToUpper());
} while (OP. ToS t ri ng(). Cont ai ns ( " S " ));
Console.WriteLine("TOTAL A PAGAR : " + PAGA);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

75
Ing. Patricio Medina
VOTACIONES POR
SECTOR
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t CANN = 0 ;
i n t CANS = 0 ;
i n t CANC = 0 ;
char OP ;
s t r i n g ZONA , l i n e a ;
CANN = 0 ;
CANC = 0 ;
CANS = 0 ;
do
{
Console.Write("Q
UE SECTOR
NORTE,CENTRO,
SUR:");
ZONA = Console.ReadLine();
switch (ZONA.ToUpper())
{
case "NORTE":
CANN = CANN + 1 ;
break;
case "CENTRO":
CANC =
CANC + 1 ;
break; 76
Ing. Patricio Medina case "SUR":
CAN
S = CANS
+ 1;
bre
}
Console.Write(" HAY OTRA PERSONA S / N : " ) ;
l i n e a =Console.ReadLine();
OP = char.Parse(linea.ToUpper());
} while (OP.ToString (). C ont a i ns ( " S " ) ) ;
Console.WriteLine("DE LA ZONA NORTE : " + CANN);
Console.WriteLine("DE LA ZONA CENTRO : " + CANC);
Console.WriteLine("DE LA ZONA SUR : " + CANS);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

PROMEDIO DE SUELDOS CERO ONEGATIVO


SALE
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
77
Ing. Patricio Medina
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ] args)
{
double SUMT = 0 ;
double SUE = 0 ;
double PROM = 0 ;
i n t CAN = 0 ;
string linea;
SUMT = 0 ;
do
{
Console.Write("DIGITE SUELDO:");
linea=Console.ReadLine();
SUE = double .P arse(linea);
i f (SUE > 0 )
{
SUMT = SUMT + SUE;
CAN = CAN + 1 ;
}
} while (SUE > 0 ) ;
PROM = SUMT / CAN;
Console.WriteLine
();
Console.WriteLine("TOTAL SUELDOS: " + SUMT);
Console.WriteLine("EMPLEADOS : " + CAN);
Console.WriteLine("PROMEDIO : " + PROM);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

78
Ing. Patricio Medina
FRASE INVERTIDA CON
WHILE
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public s t a t i c s t r i n g
M i d ( s t r i n g param, i n t
startIndex, i n t length)
{
s t r i n g r e s u l t = param.Substring(startIndex, l e n g t h ) ;
return r e s u l t ;
}
s t a t i c void M a i n ( s t r i n g [ ] args)
{
s t r i n g NOM ;
string
AUX ; int
POS = 0 ; AUX
="";
Console.Write("DIGITE UN FRASE:");
NOM = Console.ReadLine();
POS = NOM.Length ;
while ((POS > 0 ) )
{
AUX = AUX + Mid(NOM, POS-1, 1 ) ;
POS = POS - 1 ;
}
Console.WriteLine("FRASE INVERTIDO : " + AUX);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
} 79
}Ing. Patricio Medina
4. GRABAR Y EJECUTAR

EJERCICIO PROPUESTO
Concepto:
Crear un programa que pida números positivos al usuario, y vaya calculando la suma
de todos ellos (terminará cuando se teclea un número negativo o cero).

1. Abrir un nuevo Proyecto


2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ejercicio_Propuesto_6
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM, RES, TOT=0 ;
string linea;
do{
Console.
Write("ING
RESE UN 80
NUMERO : "
Ing. Patricio Medina );
l i n e a = Console.ReadLine();
NUM = i n t . P a r s e ( l i n e a ) ;
RES = NUM % 2 ;
i f (RES == 0 && NUM ! = 0 )
TOT = TOT + NUM;
else
{
}
}while(RES == 0 && NUM ! = 0 ) ;

Console.WriteLine (" La suma t o t a l es : " +TOT);


Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();

}
}
}

4. GRABAR Y EJECUTAR

81
Ing. Patricio Medina
TEMA: MANIPULACIÓN DE UN
ARREGLO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
/ / FORMA 1
/ / asignando valores
a l array a l mismo
tiempo que se de c l ara ,
/ / l a l i s t a de valores
debe i r encerrada
entre l l a v e s
{
s t r i n g [ ] VECTOR =
{ "LORENA",
"ESTEBAN",
"ARIEL"
};
byte K = 0 ;
f o r (K = 0 ; K <= 2 ;
K++)
{
Console.Write
Line(VECTOR[K]
);
}
Console.WriteLin
e(); 82
Ing. Patricio Medina / / FORMA 2
/ / declarar
primero l a v a ri a b l e
que contendrá e l
a r r a y,
20,
30,
10,
50,
60,
10,
150,
69
};
f o r (K = 0 ; K <= MILISTA.Length - 1 ; K++)
{
Console.WriteLine(MILISTA[K]);
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
}
4. GRABAR Y EJECUTAR

83
Ing. Patricio Medina
INTERCALACIÓN MAYUSCULAS Y
MINUSCULAS
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public s t a t i c s t r i n g
M i d ( s t r i n g param, i n t
startIndex, i n t length)
{
s t r i n g r e s u l t = param.Substring(startIndex, l e n g t h ) ;
return r e s u l t ;
}
s t a t i c void M a i n ( s t r i n g [ ] args)
{
s t r i n g NOM = n u l l ;
s t r i n g AUX = n u l l ;
s t r i n g LE = n u l l ;
i n t POS = 0 ;
AUX = " " ;
Console.Write("DIGITE UN FRASE:");
NOM = Console.ReadLine();
POS = 1 ;
while ((POS <= NOM.Length))
{
LE = Mid(NOM, POS-1, 1 ) ;
i f ((POS % 2 == 0 ) )
{
AUX = AUX +
LE.ToLower();
}
else
{
AUX = AUX +
LE.ToUpper(); 84
}
Ing. Patricio Medina POS = POS + 1 ;
}
Console.WriteLine("FRASE INTERCALADA : " + AUX);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

85
Ing. Patricio Medina
GENERAR NÚMEROS ALETORIOS EN UN
ARREGLO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t CAN = 0 ;
i n t POS = 0 ;
string linea;
Random rnd = new Random();
Console.Write("CUANTOS ALEATORIOS:");
linea=Console.ReadLine();
CAN = i n t . P a r s e ( l i n e a ) ;
do ubl e [ ] VEC = new double[CAN + 1 ] ;
b y t e [ ] VEC1 = new byte[CAN + 1 ] ;
/ / GENERACIÓN DE ALEATORIOS
f o r (POS = 1 ; POS <= CAN; POS++)
{
VEC[POS] = rnd.Nex t(0, 9 9 ) ;
/ / OBTENEMOS UN ENTERODE 2
CIFRAS
}
/ / SALIDA DEL ARREGLO
f o r (POS = 1 ; POS <= CAN; POS++)
{
Console.SetCursorPosition(3, POS + 2 ) ;
Console.WriteLine(VEC[POS]);
Console.SetCursorPosition(30, POS + 2 ) ;
Console.WriteLine(VEC1[POS]);
}
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine(); 86
}
Ing. Patricio Medina
}
}
4. GRABAR Y EJECUTAR

87
Ing. Patricio Medina
PASAR UNA FRASE A UN
ARREGLO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
public s t a t i c s t r i n g
M i d ( s t r i n g param, i n t
startIndex, i n t length)
{
s t r i n g r e s u l t = param.Substring(startIndex, l e n g t h ) ;
return r e s u l t ;
}
s t a t i c void M a i n ( s t r i n g [ ] args)
{
s t r i n g CAD ;
i n t POS = 0 ;
i n t LEN = 0 ;
Console.Writ
e("DIGITE
UNA
FRASE:");
CAD = Console.ReadLine();
LEN = CAD.Length;
s t r i n g [ ] VEC = new s t r i n g
[LEN + 1 ] ;
/ / PASAMOS CARACTER A CARACTER AL ARREGLO
f o r (POS = 1 ; POS <= LEN; POS++)
{
VEC[POS] = Mid(CAD, POS-1, 1 ) ;
}
/ / SALIDA
f o r (POS = 1 ; POS <= LEN; POS++)
{
Console.WriteLine(VEC[POS]);
}
88
Ing. Patricio Medina
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

SUMA ELEMENTOS PARESE IMPARES EN UN ARREGLO


1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
int

I = 0; i n t
CAN = 0 ; i n t
SUMP = 0 ; i n t
SUMI = 0 ; 89
Ing. Patricio Medina
i n t [ ] VEC =
new i n t [ 1 3 ] ;
string linea;
Console.Write("CUANTOS ELEMENTOS MÁX=12:");
linea=Console.ReadLine();
CAN = i n t . P a r s e ( l i n e a ) ;
/ / INGRESO
f o r ( I = 1 ; I <= CAN; I ++)
{
Console.Write("POSICIÓ
N { 0 } ==>", I ) ;
linea=Console.ReadLine();
VEC[I] = i n t . P a r s e ( l i n e a ) ;
}
/ / PROCESO
SUMP = 0 ;
SUMI = 0 ;
for ( I =
1 ; I <=
CAN; I ++)
{
if
((V E C
[I] %
2 ) ==
0)
{
SUMP = SUMP + VEC[I];
}
else
{
SUMI = SUMI + VEC[I];
}
}
/ / SALIDA
Console.WriteLine();
Console.WriteLine("SUMA VALORES PARES: " + SUMP);
Console.WriteLine("SUMA VALORES IMPARES: " + SUMI);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

90
Ing. Patricio Medina
MAYOR Y MENOR DE UN ARREGLO DE N
ELEMENTOS
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. Código
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace t a l l e r _ 5 4
{
class Program
{
s t a t i c void
Main(strin
g [ ] args)
{
byte I = 0 ;
byte CAN = 0 ;
i n t MAY = 0 ;
i n t MEN = 0 ;
i n t POS = 0 ;
S t r i n g cad;
Console.Write("
CUANTOS
ELEMENTOS:");
cad=Console.ReadLine();
CAN = byte.Parse(cad)
i n t [ ] VEC = new int[CAN +
1];
/ / INGRESO
f o r ( I = 1 ; I <= CAN; I +
+)
{
Console.Write("POSI
CIÓN { 0 } ==>", I ) ;
cad=Console.ReadLine();
VEC[I] = byte.Parse(cad);
}
/ / PROCESO
MAY = VEC[1]; 91
Ing. Patricio Medina
POS = 1 ;
MEN = VEC[1];
for ( I = 2; I
<= CAN; I ++)
{
{
MAY = VEC[I];
POS = I ;
}
i f ((V E C[ I ] < MEN))
MEN = VEC[I];
}
/ / SALIDA
Console.WriteLine();
Console.WriteLine("MAYOR
ES : { 0 } Y ESTA EN LA
POSICIÓN { 1 } " , MAY,
POS);
Console.WriteLine("EL MENOR ES: " + MEN);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadKey();
}
}
}

4. GRABAR Y EJECUTAR

92
Ing. Patricio Medina
OBTENER EL DÍGITO VERIFICADOR DE LA
CÉDULA
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace t a l l e r _ 5 5
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
bool VALIDO = f a l s e ;
i n t SUMP = 0 ;
i n t SUMI = 0 ;
i n t ST = 0 ;
i n t P= 0;
i n t AUX = 0 ;
i n t DV = 0 ;
S t r i n g cad;
i n t [ ] VEC =
new
int[10];
/ / INGRESO
f o r (P = 1 ;
P <= 9 ; P+
+)
{
Console
.Write("
POSICI
ÓN { 0 }
==>",
P);
cad =Console.ReadLine();
VEC[P] = i n t . P a r s e ( c a d ) ; 93
Ing. Patricio Medina
}
/ / SUMATORIA DE PARES
SUMP = 0 ;
SUMI = 0 ;
f o r (P = 2 ; P <= 8 ; P +=
/ / SUMATORIA DE IMPARES
f o r (P = 1 ; P <= 9 ; P += 2)
{
AUX = VEC[P] * 2 ;
i f (AUX > 9 )
AUX = AUX - 9 ;
SUMI = SUMI + AUX;
}
/ / OBTENCIÓN DE DÍGITO
ST = SUMP + SUMI;
DV = 10 - (ST % 1 0 ) ;
i f (DV == 10)
DV = 0 ;
Console.WriteLine("E
L DÍGITO VERIFICADOR
ES: " + DV);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

94
Ing. Patricio Medina
INSERTAR UN ELEMENTO EN UN
ARREGLO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace t a l l e r _ 5 6
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
byte I = 0 ;
byte CAN = 0 ;
byte POS = 0 ;
i n t ELE = 0 ;
S t r i n g cad;
Console.Write("
CUANTOS
ELEMENTOS : " )
;
cad= Console.ReadLine();
CAN = byte.Parse(cad); i n t [ ]
VEC = new int[CAN+1];
i n t [ ] NUEVO = new int[CAN +
2];
/ / INGRESO
f o r ( I = 1 ; I <= CAN; I ++)
{ Console.Write("POSICIÓN { 0 } ==>",
I);
cad = Console.ReadLine(); VEC[I]
= int.Parse(cad);
}
Console.Write("ELEMENTO A
INSERTAR:");
cad = Console.ReadLine(); ELE = 95
Ing. Patricio Medina
int.Parse(cad);
do {
Console.Write("POSICIÓN A
INSERTAR:");
cad = Console.ReadLine(); POS =
} while (((POS < 1) | (POS > CAN)));
/ / PROCESO
/ / TRANSLADAMOSDATOS ANTES DE LA POSICION
f o r ( I = 1 ; I <= POS - 1 ; I ++)
{
NUEVO[I] = VEC[I];
}
/ / INSERTAMOS ELEMENTO
NUEVO[POS] = ELE;
/ / TRANSLADAMOSDATOS DESPUES DE LA POSICION
f o r ( I = POS; I <= CAN; I ++) {
NUEVO[I + 1 ] = VEC[I];
}
/ / SALIDA
Console.WriteLine();
Console.WriteLine("NUEVO ARREGLO");
f o r ( I = 1 ; I <= CAN +1; I ++) {
Console.WriteLine(NUEVO[I]);
}
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadKey();
}
}
}

4. GRABAR Y EJECUTAR

96
Ing. Patricio Medina
ELIMINAR UN ELEMENTO EN UN
ARREGLO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace t a l l e r _ 5 7
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t I = 0;
i n t CAN = 0 ;
int

POS = 0 ;
S t r i n g cad;
Console.Write("
CUANTOS
ELEMENTOS : " )
;
cad =
Console.ReadLine(); CAN
= i nt . P ars e(c ad);
i n t [ ] VEC = new int[CAN+1];
i n t [ ] NUEVO = new i nt [ CA N] ;
/ / INGRESO
f o r ( I = 1 ; I <= CAN; I ++)
{ Console.Write("POSICIÓN { 0 } ==>",
I);
cad = Console.ReadLine(); VEC[I]
= int.Parse(cad);
}
do {
Console.Write("POSICIÓN A 97
Ing. Patricio Medina ELIMINAR:");
cad = Console.ReadLine(); POS =
int.Parse(cad);
} while (((POS < 1) | (POS > CAN)));
/ / PROCESO
NUEVO[I] = VEC[I];
}
/ / TRANSLADAMOSDATOS DESPUES DE LA POSICIÓN
f o r ( I = POS+1; I <= CAN; I ++) {
NUEVO[I - 1 ] = VEC[I];
}
/ / SALIDA
Console.WriteLine();
Console.WriteLine("NUEVO ARREGLO");
f o r ( I = 1 ; I <= CAN - 1 ; I ++) {
Console.WriteLine(NUEVO[I]);
}
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

98
Ing. Patricio Medina
SUMA DE DOS ARREGLOS DE 5
ELEMENTOS
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
byte I = 0 ;
i n t [ ] A = new i n t [ 1 0 ] ;
i n t [ ] B = new i n t [ 1 0 ] ;
i n t [ ] S = new i n t [ 6 ] ;
string linea;
/ / INGRESO
Console.WriteLine("PRIMERO SEGUNDO
RESULTADO"); f o r ( I = 1 ; I <= 5 ; I ++) {
/ / ARREGLO 1
Console.SetCursorPosition(3, I + 2 ) ;
linea=Console.ReadLine();
A [ I ] = i n t . P a rs e ( l i n e a ) ;
/ / ARREGLO 2
Console.ReadLine(); Console.SetCursorPosition(10, I +
2 ) ; linea=Console.ReadLine();
B [ I ] = i n t . P a rs e
(linea); S[I] = A[I] +
B[I];
}
/ / SALIDA
f o r ( I = 1 ; I <= 5 ; I ++) {
Console.SetCursorPosition(18, I +
2 ) ; Co ns ol e . Wri t eLi n e(S [ I ] );
} 99
Ing. Patricio Medina
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

100
Ing. Patricio Medina
SUMA DE DOS ARREGLOS DE 5 ELEMENTOS
INTERCALADO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t I = 0;
i n t F = 0;
i n t [ ] A = new i n t [ 1 0 ] ;
i n t [ ] B = new i n t [ 1 0 ] ;
i n t [ ] S = new i n t [ 6 ] ;
string linea;
/ / INGRESO
Console.WriteLine("PRIMERO SEGUNDO RESULTADO");
f o r ( I = 1 ; I <= 5 ; I ++)
{
/ / ARREGLO 1
Console.SetCursorPosition(3, I + 2 ) ;
l i n e a = Console.ReadLine();
A [ I ] = int.Parse(linea);
/ / ARREGLO 2
Console.SetCursorPosition(10, I + 2 ) ;
l i n e a = Console.ReadLine();
B [ I ] = int.Parse(linea);
/ / PROCESO
F = 5;
/ / POSICIÓN DE ARREGLO B
f o r ( I = 1 ; I <= 5 ; I ++)
{
101
Ing. Patricio Medina
S [ I ] = A [ I ] + B[F];
F = F - 1;
}
/ / SALIDA
f o r ( I = 1 ; I <= 5 ; I ++)
{
Console.SetCursorPosition(18, I + 2 ) ;
Co ns ol e . Wri t eLi n e(S [ I ] );
}
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
}

4. GRABAR Y EJECUTAR

102
Ing. Patricio Medina
EJERCICIO PROPUESTO
Concepto:
Desarrollar un programa que permita cargar 5 nombres de personas y sus edades respectivas.
Luego de realizar la carga por teclado de todos los datos imprimir los nombres de las personas
mayores de edad (mayores o iguales a 18 años)

1. Abrir un nuevo Proyecto


2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace PruebaVector10
{
class PruebaVector10
{
p r i v a t e s t r i n g [ ] nombres;
p r i v a t e i n t [ ] edades;

p u b l i c void Cargar()
{
nombres = new s t r i n g [ 5 ] ;
edades = new i n t [ 5 ] ;
for ( i n t f = 0; f <
nombres.Length; f ++)
{
Console.Write("Ingrese nombre:");
nombres[f] = Console.ReadLine();
Console.Write("Ingrese e d a d : " ) ;
string linea;
l i n e a = Console.ReadLine();
edades[f] = i n t . P a r s e ( l i n e a ) ;
}
}

p u b l i c void MayoresEdad()
{
103
Ing. Patricio Medina
Console.WriteLine("Personas mayores de e d a d . " ) ;
f o r ( i n t f = 0 ; f < nombres.Length; f ++)
{
i f (ed ades [ f ] >= 18)
{
Console.WriteLine(nombres[f]);
}
}
Console.ReadKey();
}

s t a t i c void M a i n ( s t r i n g [ ] args)
{
PruebaVector10 pv = new PruebaVector10();
pv. C arga r();
pv.MayoresEdad();
}
}
}

4. GRABAR Y EJECUTAR

104
Ing. Patricio Medina
EJERCICIO PROPUESTO
Concepto:
Confeccionar un programa que permita cargar los nombres de 5 operarios y sus sueldos
respectivos. Mostrar el sueldo mayor y el nombre del operario.

1. Abrir un nuevo Proyecto


2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace PruebaVector11
{
class PruebaVector11
{
p r i v a t e s t r i n g [ ] nombres;
p r i v a t e f l o a t [ ] sueldos;

p u b l i c void Cargar()
{
nombres = new s t r i n g [ 5 ] ;
sueldos = new f l o a t [ 5 ] ;
for ( i n t f = 0; f <
nombres.Length; f ++)
{
Console.Write("Ingrese e l nombre de l empleado:");
nombres[f] = Console.ReadLine();
Console.Write("Ingrese e l s u e l d o : " ) ;
string linea;
l i n e a = Console.ReadLine();
sueldos[f] = float.Parse(linea);
}
}

p u b l i c void MayorSueldo()
{
105
Ing. Patricio Medina
f l o a t mayor;
i n t pos;
mayor =
sueldos[0];
pos = 0 ;
for (i nt f =
1; f <
nombres.Len
gth; f ++)
{
if
(sueldo
s[f] >
mayor)
{
mayor = s u e l d o s [ f ] ;
pos = f ;
}
}
Console.WriteLine("El empleado con sueldo mayor es " + nombres[pos]);
Console.WriteLine("Tiene un sueldo:" + mayor);
Console.ReadKey();
}

s t a t i c void M a i n ( s t r i n g [ ] args)
{
PruebaVector11 pv = new PruebaVector11();
pv. C arga r();
pv.MayorSueldo();
}
}
}

4. GRABAR Y EJECUTAR

106
Ing. Patricio Medina
NÚMERO DECIMAL A
BINARIO
1. Abrir un nuevo Proyecto

2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
const i n t BASE =2;
i n t NUM = 0 ;
i n t AUX = 0 ;
i n t POS = 0 ;
i n t I = 0;
i n t [ ] VEC = new i n t [ 2 1 ] ;
string linea;
Console.Write("DIGITE UN
NÚMERO:");
l i n e a = Console.ReadLine();
NUM = i n t . P a r s e ( l i n e a ) ;
POS = 1 ;
while ((NUM >= BASE))
{
AUX = NUM % BASE;
VEC[POS] = AUX;
POS = POS + 1 ; NUM
= NUM / BASE;
}
VEC[POS] = NUM;
/ / SALIDA
f o r ( I = POS; I >= 1 ; I
+= - 1 ) 107
Ing. Patricio Medina
{
Console.Write(VEC[I] + " " ) ;
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

108
Ing. Patricio Medina
NÚMERO DECIMAL A
OCTAL
1. Abrir un nuevo Proyecto

2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
const i n t BASE = 8 ;
i n t NUM = 0 ;
i n t AUX = 0 ;
i n t POS = 0 ;
i n t I = 0;
string linea;
i n t [ ] VEC =
new i n t [ 2 1 ] ;
Console.Write("DIGITE UN NÚMERO:");
l i n e a = Console.ReadLine();
NUM = i n t . P a r s e ( l i n e a ) ;
POS = 1 ;
while ((NUM >= BASE))
{
AUX = NUM % BASE;
VEC[POS] = AUX;
POS = POS + 1 ; NUM
= NUM / BASE;
}
VEC[POS] = NUM;
/ / SALIDA
f o r ( I = POS; I >= 1 ; I
+= - 1 ) 109
Ing. Patricio Medina
{
Console.Write(VEC[I] + " " ) ;
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

110
Ing. Patricio Medina
NÚMERO DECIMAL A
HEXADECIMAL
1. Abrir un nuevo Proyecto

2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
const i n t BASE = 16;
i n t NUM = 0 ;
i n t AUX = 0 ;
i n t POS = 0 ;
i n t I = 0;
s t r i n g [ ] VEC = new s t r i n g [ 2 1 ] ;
string DAT;
string linea;
Console.Write("DIGITE UN NÚMERO:");
l i n e a = Console.ReadLine();
NUM = i n t . P a r s e ( l i n e a ) ;
/ / PROCESO
POS = 1 ;
while
((NUM >=
BASE))
{
AUX =
NUM
%
BASE;
switch
(AUX) 111
Ing. Patricio Medina {
ca
se
1
0:
DAT = " B " ;
br eak;
case 12:
DA
T=
"C";
br eak;
case 13:
DA
T=
"D";
br eak;
case 14:
DA
T=
"E";
br eak;
case 15:
DA
T=
"F";
br eak;
default:
DA
T=
AUX.T
oStrin
g();
br
eak;
}
VEC[POS] =
DAT; POS = POS + 1 ;
NUM = NUM / BASE;
}
/ / FIN DEL WHILE
switch (NUM)
{
case 10:
DAT = " A " ;
br eak;
case 11:
DA
T=
"B";
br eak;
case 12:
DA
T=
"C";
br eak;
case 13:
DA
T=
"D";
br eak;
case 14:
DA
T=
"E"; 112
Ing. Patricio Medina br eak;
case 15:
DA
T=
"F";
}

4. GRABAR Y EJECUTAR

113
Ing. Patricio Medina
EJERCICIO PROPUESTO
Concepto:
Confeccionar un programa que permita obtener una serie de sumas ejemplo primer número=2,
segundo número=4; suma1=2, suma2=6; es decir las sumas son resultado de la suma anterior
mas el numero ingresado correspondiente.

1. Abrir un nuevo Proyecto


2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
p u b l i c class Ejemplo36
{
p u b l i c s t a t i c void Main()
{
i n t [ ] numero = new i n t [ 5 ] ; / * Un array de 5 números enteros * /
i n t suma; / * Un entero que será l a suma * /
i n t i ; / * Para re c o rre r l o s elementos * /
f o r ( i = 0 ; i <= 4 ; i + + ) / * Pedimos l o s datos * /
{
Console.Write("Introduce e l dato numero { 0 } : " , i + 1 ) ;
numero[i] = Convert.ToInt32(Console.ReadLine());
}
suma = 0 ; / * Valor i n i c i a l de l a suma * /
f o r ( i = 0 ; i <= 4 ; i + + ) / * Y hallamos l a suma r e p e t i t i v a * /
{
suma += nu m ero [ i ] ;
Console.WriteLine("Su suma es { 0 } " , suma);
}
Console.ReadKey();
}
}

114
Ing. Patricio Medina
4. GRABAR Y EJECUTAR

ORDENAMIENTO DE UN
ARREGLO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
int

I = 0; i n t

K = 0; i n t

CAN = 0 ; i n t

AUX = 0 ;
115
Ing. Patricio Medina
string linea;
Console.Write("
CUANTOS
ELEMENTOS
MÁX=12:");
i n t [ ] VEC = new int[CAN + 1 ] ;
/ / INGRESO
f o r ( I = 1 ; I <= CAN; I ++)
{
Console.Write("POSICIÓN { 0 } ==>", I ) ;
l i n e a = Console.ReadLine();
VEC[I] = i n t . P a r s e ( l i n e a ) ;
}
/ / PROCESO
f o r ( I = 1 ; I <= CAN; I ++)
{
f o r (K = I ; K <= CAN; K++)
{
i f ((VEC[K] > V E C[ I ] ))
{
AUX = VEC[K];
VEC[K] = VEC[I];
VEC[I] = AUX;
}
}
}
Console.WriteLine();
/ / ARREGLO
Console.WriteLine("ARREGLO ORDENADO DESCENDENTE");
f o r ( I = 1 ; I <= CAN; I ++)
{
Console.WriteLine(VEC[I]);
}
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

116
Ing. Patricio Medina
ORDENAMIENTO DE UN ARREGLO MÉTODO
BURBUJA
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t I = 0;
i n t K= 0;
i n t CAN = 0 ;
i n t AUX = 0 ;
string linea;
Console.Write("
CUANTOS
ELEMENTOS
MÁX=12:");
linea=Console.ReadLine();
CAN = i n t . P a r s e ( l i n e a ) ;
i n t [ ] VEC = new int[CAN +
1];
/ / INGRESO
f o r ( I = 1 ; I <= CAN; I ++)
{
Console.Write("POSICI
ÓN { 0 } ==>", I ) ;
l i n e a = Console.ReadLine();
VEC[I] = i n t . P a r s e ( l i n e a ) ;
}
/ / PROCESO
f o r ( I = 1 ; I <= CAN - 1 ; I ++)
{ 117
Ing. Patricio Medina f o r (K = I + 1 ; K <= CAN; K++)
{
i f ((V E C[ I ] < VEC[K]))
{
AUX = VEC[K];
VEC[K] = VEC[I];
VEC[I] = AUX;
}
}
}
Console.WriteLine();
/ / SALIDA
Console.WriteLine("ARREGLO ORDENADO DESCENDENTE");
f o r ( I = 1 ; I <= CAN; I ++)
{
Console.WriteLine(VEC[I]);
}
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

118
Ing. Patricio Medina
BÚSQUEDA DE UN ELEMENTO EN UN
ARREGLO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t I = 0;
i n t CAN = 0 ;
i n t TOT = 0 ;
i n t BUS = 0 ;
string linea;
Console.Write("
CUANTOS
ELEMENTOS:");
l i n e a =Console.ReadLine();
CAN = i n t . P a r s e ( l i n e a ) ;
i n t [ ] VEC = new int[CAN +
1];
/ / INGRESO
f o r ( I = 1 ; I <= CAN; I ++)
{
Console.Write("POSICIÓ
N { 0 } ==>", I ) ;
l i n e a = Console.ReadLine();
VEC[I] = i n t . P a r s e ( l i n e a ) ;
}
Console.Write("ELEMENTO A
BUSCAR:");
l i n e a = Console.ReadLine();
BUS = i n t . P a r s e ( l i n e a ) ; 119
/ / PROCESO
Ing. Patricio Medina
TOT = 0 ;
f o r ( I = 1 ; I <= CAN; I ++)
{
i f ((V E C[ I ] == BUS))
{
TOT = TOT + 1 ;
}
}
/ / SALIDA
Console.WriteLine();
Console.WriteLine("EXISTE { 0 } NÚMEROS { 1 } " , TOT, BUS);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

120
Ing. Patricio Medina
BÚSQUEDA BINARIA DE UN ELEMENTO EN UN
ARREGLO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t I = 0;
i n t CAN = 0 ;
i n t J = 0;
i n t ALTO = 0 ;
i n t BAJO = 0 ;
i n t CENTRAL =
0;
i n t BUS = 0 ;
i n t AUX = 0 ;
string linea;
Random rnd = new Random();
Console.Write("CUANTOS ELEMENTOS:");
linea=Console.ReadLi
ne(); CAN =
int.Parse(linea);
i n t [ ] VEC = new int[CAN +
1 ] ; bool ENCONTRADO = f a l s e ;
/ / INGRESO
f o r ( I = 1 ; I <= CAN; I ++)
{
VEC[I] = rnd.Nex t(0,
99);
}
/ / SALIDA DEL ARREGLO 121
ALEATORIO
Ing. Patricio Medina f o r ( I = 1 ; I <= CAN;
I ++)
{
Console.SetCursorPosition(3, I + 2 ) ;
Console.WriteLine(VEC[I]);
}
/ / PRIMERO ORDENAMOS EL ARREGLO
f o r ( J = 1 ; J <= CAN; J++)
{
f o r ( I = 1 ; I <= CAN - 1 ;
I ++)
{
i f ((V E C[ I ] > VEC[I +
1]))
{
AUX = VEC[I];
VEC[I] = VEC[I + 1 ] ;
VEC[I + 1 ] = AUX;
}
}
}
/ / SALIDA DEL ARREGLO ORDENADO
f o r ( I = 1 ; I <= CAN; I ++)
{
Console.SetCursorPosition(10, I + 2 ) ;
Console.WriteLine(VEC[I]);
}
/ / AHORA SI LA BÚSQUEDA
Console.Write("ELEMENTO A BUSCAR:");
l i n e a = Console.ReadLine();
BUS = i n t . P a r s e ( l i n e a ) ;
BAJO = 1 ;
ALTO = CAN;
/ / CENTRAL
= (BAJO +
ALTO) / 2
while
(((BAJO <=
ALTO) &
(ENCONTRADO
== f a l s e ) ) )
{
CENTRAL = (BAJO + ALTO) / 2 ;
i f ((VEC[CENTRAL] == BUS))
{
ENCONTRADO = t r u e ;
}
else
{
i f ((VEC[CENTRAL] > BUS))
{
ALTO = CENTRAL - 1 ;
}
else
{
BAJO = CENTRAL + 1 ;
}
}
}
i f ((ENCONTRADO))
{
Console.WriteLine("{0} 122
Encontrado en l a posicion
Ing. Patricio Medina
{ 1 } " , BUS, CENTRAL);
}
else
{
Console.WriteLine("No e x i s t e
}
}
}

4. GRABAR Y EJECUTAR

EJERCICIO PROPUESTO
Concepto:
Crear una matriz de n * m filas (cargar n y m por teclado) Imprimir la matriz completa y la
última fila.

1. Abrir un nuevo Proyecto


2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

using System;
using System.Collections.Generic;

123
Ing. Patricio Medina
using System.Linq;
using System.Text;

namespace Matriz5
{
class Matriz5
{
private
int[,]
mat;

public
void
Cargar()
{
Console.Write("Cuantas f i l a t i e n e l a m a t r i z : " ) ;
string linea;
l i n e a = Console.ReadLine();
i n t f i l a s = int.Parse(linea);
Console.Write("Cuantas columnas t i e n e l a m a t r i z : " ) ;
l i n e a = Console.ReadLine();
i n t columnas = i n t . P a r s e ( l i n e a ) ;
mat = new i n t [ f i l a s , columnas];
for ( i n t f = 0; f <
mat.GetLength(0); f ++)
{
for ( i n t c = 0; c <
mat.GetLength(1); c++)
{
Console.Write("Ingrese componente:");
l i n e a = Console.ReadLine();
mat[f, c] = int.Parse(linea);
}
}
}

p u b l i c void I m p r i m i r ( )
{
f o r ( i n t f = 0 ; f < mat.GetLength(0); f ++)
{
f o r ( i n t c = 0 ; c < mat.GetLength(1); c++)
{
Console.Write(mat[f, c ] + " " ) ;
}
Console.WriteLine();
}
}

p u b l i c void I m p r i m i r U l t i m a F i l a ( )
{
Console.WriteLine("Ultima f i l a " ) ;
f o r ( i n t c = 0 ; c < mat.GetLength(1); c++)
{
Console.Write(mat[mat.GetLength(0) - 1 , c ]
+" ");
}
}

s t a t i c void M a i n ( s t r i n g [ ] args) 124


Ing. Patricio
{ Medina
Matriz5 ma = new M a t r i z 5 ( ) ;
ma.Cargar();
m a . I m p ri m i r();
ma. I mpr i mi r Ul t i maFi l a(
}
}
}

4. GRABAR Y EJECUTAR

TABLAS DE MULTIPLICAR EN UNA MATRIZ DE


NxN
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
125
Ing. Patricio Medina
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ] args)
{
i n t F = 0;
i n t C = 0;
i n t N = 0;
i n t M = 0;
string linea;
/ / GENERO LOS NÚMEROS
Console.Write("FILAS DE LA MATRIZ:");
l i n e a = Console.ReadLine();
N = int.Parse(linea);
Console.Write("COLUMNAS DE
LA MATRIZ:");
l i n e a = Console.ReadLine();
M = int.Parse(linea);
i n t [ , ] MAT = new i n t [ N + 1 , M + 1 ] ;
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= M; C++)
{
MAT[F, C] = F * C;
}
}
/ / SALIDA
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= M; C++)
{
/ / APROVECHAMOS CICLOS Y
GENERAMOS POSICIÓN EN
PANTALLA
/ / PARA COLUMNA Y FILA
Console.SetCursorPosition(C * 4 , F + 1 ) ;
Console.Write(MAT[F, C ] ) ;
}
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

126
Ing. Patricio Medina
GENERAR ALEATORIOS EN UNA MATRIZ DE
5x5
1. Abrir un nuevo Proyecto

2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t F = 0;
int

C = 0;
i n t [ , ] MAT = new i n t [ 6 , 6 ] ;
Random rnd = new Random();
/ / GENERO LOS NÚMEROS f o r
(F = 1 ; F <= 5 ; F++)
{
f o r (C = 1 ; C <= 5 ; C+
+)
{
MAT[F, C] =
rnd.Nex t(0, 9 9 ) ;
}
}
/ / SALIDA
f o r (F = 1 ; F <= 5 ; F++)
{
f o r (C = 1 ; C <= 5 ; C+
+)
{
/ / APROVECHAMOS 127
Ing. Patricio Medina CICLOS Y
GENERAMOS
POSICIÓN EN
PANTALLA
/ / PARA COLUMNA Y
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

SUMAR ELEMENTOS DE UNA MATRIZ DE


NxN
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args) 128
Ing. Patricio Medina
{
i n t F = 0;
i n t C = 0;
int

N = 0; i n t
SUM = 0 ;
string linea;
/ / INGRESO
Console.Write("
TAMAÑO DE LA
MATRIZ:");
linea=Console.ReadLine();
N = int.Parse(linea);
i n t [ , ] MAT = new i n t [ N + 1 , N + 1 ] ;
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N; C++)
{
Console.SetCursorPosition(C * 4 , F + 1 ) ;
l i n e a = Console.ReadLine();
MAT[F, C] = i n t . P a r s e ( l i n e a ) ;
}
}
/ / PROCESO
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N; C++)
{
SUM = SUM + MAT[F, C ] ;
}
}
/ / SALIDA
Console.WriteLine();
Console.WriteLine("SUMA TOTAL ES:" + SUM);
Console.WriteLine("PROMEDIO TOTAL ES:" + SUM
/ (N * N ) ) ;
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

129
Ing. Patricio Medina
SUMAR ELEMENTOS DE FILA Y UNA COLUMNA MATRIZ DE
5x5
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t F = 0;
i n t C = 0;
i n t SUMF = 0 ;
i n t SUMC = 0 ;
string linea;
/ / INGRESO
i n t [ , ] MAT = new i n t [ 6 , 6 ] ;
f o r (F = 1 ; F <= 5 ; F++)
{
f o r (C = 1 ; C <= 5 ; C++)
{
Console.SetCursorPosition(C * 4 , F + 1 ) ;
l i n e a = Console.ReadLine();
MAT[F, C] = i n t . P a rs e ( l i n e a ) ;
}
}
/ / FILA 2
SUMF = 0 ;
f o r (C = 1 ; C <= 5 ; C++)
{
SUMF = SUMF + MAT[2, C ] ;
}
/ / COLUMNA 3
130
Ing. Patricio Medina
SUMC = 0 ;
f o r (F = 1 ; F <= 5 ; F++)
{
SUMC = SUMC + MAT[F, 3 ] ;
}
/ / SALIDA
Console.WriteLine();
Console.WriteLine("SUMA FILA 2 ES:" + SUMF);
Console.WriteLine("SUMA COLUMNA 3 ES:" + SUMC);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

SUMAR ELEMENTOS DE DIAGONAL PRINCIPAL Y


SECUNDARIA

MATRIZ DE NxN
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

131
Ing. Patricio Medina
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t F = 0;
int

C = 0; i n t

N = 0; i n t
SUMP = 0 ; i n t
SUMS = 0 ;
string linea;
/ / INGRESO
/ / PARA COMODIDAD GENERAMOS VALORES PARA LA MATRIZ
Console.Write("TAMAÑO DE LA MATRIZ:");
Random rnd = new Random();
l i n e a =Console.ReadLine();
N = int.Parse(linea);
i n t [ , ] MAT = new i n t [ N + 1 , N + 1 ] ;
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N; C++)
{
MAT[F, C] = rnd.Nex t(0, 9) ;
Console.SetCursorPosition(C * 4 , F + 1 ) ;
Console.Write(MAT[F, C ] ) ;
}
}
/ / DIAGONAL PRINCIPAL
SUMP = 0 ;
f o r (F = 1 ; F <= N; F++)
{
SUMP = SUMP +
MAT[F, F ] ;
}
/ / DIAGONAL SECUNDARIA
SUMS = 0 ;
C = N;
f o r (F = 1 ; F <= N; F++)
{
SUMS = SUMS + MAT[F, C ] ;
C = C - 1;
}
/ / SALIDA
Console.WriteLine();
Console.WriteLine("SUMA DIAGONAL PRINCIPAL ES : " + SUMP);
Console.WriteLine("SUMA DIAGONAL SECUNDARIA ES:" + SUMS);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
} 132
}
Ing. Patricio Medina
}
4. GRABAR Y EJECUTAR

FORMAR LA LETRA A EN UNA MATRIZ DE


NxN
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t F = 0;
i n t C = 0;
i n t N = 0;
i n t MI = 0 ;
string linea;
/ / MATRIZ EN
BLANCO
133
Ing. Patricio Medina
Console.Write("TAMAÑO DE LA MATRIZ IMPAR:");
l i n e a = Console.ReadLine();
N = int.Parse(linea ) ;
N = (N % 2 == 0 ? N + 1 : N );
s t r i n g [ , ] MAT = new s t r i n g
[N + 1 , N + 1 ] ;
/ / MATRIZ EN BLANCO
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N; C++)
{
MAT[F, C] = " " ;
/ / UN ESPACIO EN
BLANCO
}
}
/ / FORMAMOS LA LETRA
MI = N / 2 + 1 ;
f o r (F = 1 ; F <= N; F+
+)
{
MAT[F, 1 ] = " A " ;
MAT[F, N] = " A " ;
MAT[MI, F] = " A " ;
MAT[1, F] = " A " ;
}
/ / SALIDA
f o r (F = 1 ; F <= N; F+
+)
{
f o r (C = 1 ; C <=
N; C++)
{
Console.SetCursorPosition(C, F + 1 ) ;
Console.Write(MAT[F, C ] ) ;
}
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

134
Ing. Patricio Medina
EJERCICIO PROPUESTO
Concepto:
Se tiene la siguiente información:
· Nombres de 4 empleados.
·Ingresos en concepto de sueldo, cobrado por cada empleado, en los últimos 3 meses.
Confeccionar el programa para:
a) Realizar la carga de la información mencionada.
b)Generar un vector que contenga el ingreso acumulado en sueldos en los últimos 3 meses para
cada empleado.
c) Mostrar por pantalla el total pagado en sueldos a todos los empleados en los últimos 3 meses
d) Obtener el nombre del empleado que tuvo el mayor ingreso acumulado

1. Abrir un nuevo Proyecto


2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Matriz9
{
class Matriz9
{
p r i v a t e s t r i n g [ ] empleados;
p r i v a t e i n t [ , ] sueldos;
private i n t [ ] sueldostot;

p u b l i c void Cargar()
{
empleados = new S t r i n g [ 4 ] ;
sueldos = new i n t [ 4 , 3 ] ;
for ( i n t f = 0; f <
empleados.Length; f ++)
{
Console.Write("Ingrese e l nombre de l empleado:");
empleados[f] = Console.ReadLine();
f o r ( i n t c = 0 ; c < sueldos.GetLength(1); c++)
135
Ing. Patricio Medina
{
Console.Write("Ingrese s u e l d o : " ) ;
string linea;
l i n e a = Console.ReadLine();
sueldos[f, c ] = int.Parse(linea);
}
}
}

p u b l i c void CalcularSumaSueldos()
{
sueldostot = new i n t [ 4 ] ;
f o r ( i n t f = 0 ; f < sueldos.GetLength(0);
f ++)
{
i n t suma = 0 ;
for ( i n t c = 0; c <
sueldos.GetLength(1); c++)
{
suma = suma + s u e l d o s [ f , c ] ;
}
s u e l d o s t o t [ f ] = suma;
}
}

p u b l i c void ImprimirTotalPagado()
{
Console.WriteLine("Total de sueldos pagados por empleado.");
f o r ( i n t f = 0 ; f < sueldostot.Length; f ++)
{
Console.WriteLine(empleados[f] + " - " + s u e l d o s t o t [ f ] ) ;
}
}

p u b l i c void EmpleadoMayorSueldo()
{
i n t may = s u e l d o s t o t [ 0 ] ;
s t r i n g nom = empleados[0];
for ( i n t f = 0; f <
sueldostot.Length; f ++)
{
i f (sueldostot[f] >
may)
{
may = s u e l d o s t o t [ f ] ;
nom = empleados[f];
}
}
Console.WriteLine("El empleado con mayor sueldo es " + nom + " que t i e n e un
sueldo de " + may);
}

s t a t i c void M a i n ( s t r i n g [ ] args)
{
Matriz9 ma = new
M a t r i z 9 ( ) ; ma.Cargar();
ma.CalcularSumaSueldos();
ma.ImprimirTotalPagado();
ma.EmpleadoMayorSueldo(); 136
Console.ReadKey();
Ing. Patricio Medina
}
}
}

4. GRABAR Y EJECUTAR

137
Ing. Patricio Medina
FORMAR LA LETRA R EN UNA MATRIZ DE
NxN
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t F = 0;
i n t C = 0;
i n t N = 0;
i n t MI = 0 ;
i n t FI = 0 ;
string linea;
/ / MATRIZ EN
BLANCO
Console.Write("
TAMAÑO DE LA
MATRIZ
IMPAR:");
l i n e a = Console.ReadLine();
N = int.Parse(linea);
N = (N % 2 == 0 ? N + 1 : N );
s t r i n g [ , ] MAT = new s t r i n g
[N + 1 , N + 1 ] ;
/ / MATRIZ EN BLANCO
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N; C++)
{
MAT[F, C] = " " ;
/ / UN ESPACIO EN 138
Ing. Patricio Medina BLANCO
}
}
/ / FORMAMOS LA LETRA
MI = N / 2 + 1 ;
f o r (F = 1 ; F <= N; F++)
{
MAT[F, 1 ] = " A " ;
MAT[MI, F] = " A " ;
MAT[1, F] = " A " ;
}
FI = MI;
/ / PARA EMPEZARDESDE FILA DE LA MITAD f o r
(F = 1 ; F <= MI; F++)
{
MAT[F, N] = " A " ;
MAT[FI, F I ] = " A " ;
FI = FI + 1 ;
}
/ / SALIDA
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N;
C++)
{
Console.SetCursorPosition(C, F + 1 ) ;
Console.Write(MAT[F, C ] ) ;
}
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

139
Ing. Patricio Medina
SUMAR ELEMENTOS DE DIAGONAL PRINCIPAL Y
SECUNDARIA

MATRIZ DE NxN
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t F = 0;
i n t C = 0;
i n t N = 0;
i n t SUMP = 0 ;
i n t SUMS = 0 ;
string linea;
/ / INGRESO
/ / PARA COMODIDAD GENERAMOS VALORES PARA LA MATRIZ
Console.Write("TAMAÑO DE LA MATRIZ:");
Random rnd = new Random();
l i n e a =Console.ReadLine();
N = int.Parse(linea);
i n t [ , ] MAT = new i n t [ N + 1 , N + 1 ] ;
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N; C++)
{
MAT[F, C] = rnd.Nex t(0, 9 ) ;
Console.SetCursorPosition(C * 4 , F + 1 ) ;
Console.Write(MAT[F, C ] ) ;
}
140
Ing. Patricio Medina
}
/ / DIAGONAL PRINCIPAL
SUMP = 0 ;
f o r (F = 1 ; F <= N; F++)
{
SUMP = SUMP +
MAT[F, F ] ;
}
/ / DIAGONAL SECUNDARIA
SUMS = 0 ;
C = N;
f o r (F = 1 ; F <= N; F++)
{
SUMS = SUMS + MAT[F, C ] ; C
= C - 1;
}
/ / SALIDA
Console.WriteLine();
Console.WriteLine("SUMA DIAGONAL PRINCIPAL ES : " + SUMP);
Console.WriteLine("SUMA DIAGONAL SECUNDARIA ES:" + SUMS);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

141
Ing. Patricio Medina
NÚMERO MAYOR Y MENOR EN UNA MATRIZ DE
NxN
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t F = 0;
i n t C = 0;
i n t N = 0;
i n t MAY = 0 ;
i n t MEN = 0 ;
string linea;
/ / INGRESO
/ / PARA COMODIDAD GENERAMOS VALORES PARA LA MATRIZ
Console.Write("TAMAÑO DE LA MATRIZ:");
Random rnd = new Random();
l i n e a = Console.ReadLine();
N = int.Parse(linea);
i n t [ , ] MAT = new i n t [ N + 1 , N + 1 ] ;
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N; C++)
{
MAT[F, C] = rnd.Nex t(0, 9 9 ) ;
Console.SetCursorPosition(C * 4 , F + 1 ) ;
Console.Write(MAT[F, C ] ) ;
}
}
/ / PROCESO
142
Ing. Patricio Medina
MAY = MAT[1, 1 ] ;
MEN = MAT[1, 1 ] ;
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N; C++)
{
i f ((MAT[F, C] > MAY))
MAY = MAT[F, C ] ;
i f ((MAT[F, C] < MEN))
MEN = MAT[F, C ] ;
}
}
/ / SALIDA
Console.WriteLine(); Console.WriteLine("NÚMERO
MAYOR ES: " + MAY); Console.WriteLine("NÚMERO
MENOR ES: " + MEN); Console.Write("Pulse una
Te c l a : " ) ; Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

143
Ing. Patricio Medina
ORDENAMIENTO DE UNA MATRIZ DE
NxN
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t F = 0;
i n t C = 0;
i n t I = 0;
i n t K= 0;
i n t N = 0;
i n t AUX = 0 ;
string
cadena;
/ / INGRESO
/ / PARA COMODIDAD GENERAMOS VALORES PARA LA MATRIZ
Console.Write("TAMAÑO DE LA MATRIZ: " ) ;
cadena =Console.ReadLine();
Random rnd = new Random();
N = int.Parse(cadena);
i n t [ , ] MAT = new i n t [ N + 1 , N + 1 ] ;
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N; C++)
{
MAT[F, C]

= rnd.Nex t(0, 100);


Console.SetCursorPosition(C * 4 , F + 1 ) ;
Console.Write(MAT[F, C ] ) ;
}
} 144
/ / PROCESO
Ing. Patricio Medina
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N; C++)
{
f o r ( I = 1 ; I <= N; I ++)
{
f o r (K = 1 ; K <= N; K++)
{
i f ((MAT[F, C] < MAT[I, K ] ) )
{
AUX = MAT[F, C ] ; MAT[F,
C] = MAT[I, K ] ; MAT[I,
K] = AUX;
}
}
}
}
}
/ / SALIDA
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N;
C++)
{
Console.SetCursorPosition(C * 4 , F + 1 0 ) ;
Console.Write(MAT[F, C ] ) ;
}
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

145
Ing. Patricio Medina
SUMA DE MATRICES DE
5x5
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
Random rnd = new Random();
i n t F = 0;
i n t C = 0;
i n t [ , ] MATA = new i n t [ 1 0 0 , 1 0 0 ] ;
i n t [ , ] MATB = new i n t [ 1 0 0 , 1 0 0 ] ;
i n t [ , ] MATC = new i n t [ 6 , 6 ] ;
/ / INGRESO
/ / PARA COMODIDAD GENERAMOS VALORES PARA LAS MATRICES f o r
(F = 1 ; F <= 5 ; F++) {
f o r (C = 1 ; C <= 5 ; C++)
{ MATA[F, C] = rnd.Nex t(0,
10);
MATB[F, C] = rnd.Nex t(0,
10);
/ / SALIDA MATRIZ A
Console.SetCursorPosition(C * 4 , F ) ;
Console.Write(MATA[F, C ] ) ;
/ / SALIDA MATRIZ B
Console.SetCursorPosition(C * 4 , F + 6 ) ;
Console.Write(MATB[F, C ] ) ;
}
}
/ / PROCESO
f o r (F = 1 ; F <= 5 ; F++) { 146
Ing. Patricio Medina f o r (C = 1 ; C <= 5 ; C++) {
MATC[F, C] = MATA[F, C] + MATB[F, C ] ;
}
}
/ / SALIDA
Console.WriteLine();
Console.WriteLine("MATRIZ RESULTANTE");
f o r (F = 1 ; F <= 5 ; F++) {
f o r (C = 1 ; C <= 5 ; C++) {
Console.SetCursorPosition(C * 4 , F + 1 3 ) ;
Console.Write(MATC[F, C ] ) ;
}
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

147
Ing. Patricio Medina
MULTIPLICACIÓN DE MATRICES DE
4x4
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t N = 4;
/ / TAMAÑO DE LA MATRIZ
i n t F = 0;
i n t C = 0;
i n t K= 0;
i n t [ , ] MATA = new i n t [ 10 0, 10 0] ;
i n t [ , ] MATB = new i n t [ 10 0, 10 0] ;
i n t [ , ] MATC = new i n t [ N + 1 , N + 1 ] ;
/ / INGRESO
/ / PARA COMODIDAD GENERAMOS VALORES
PARA LAS MATRICES
Random rnd = new Random();
f o r (F = 1 ; F <= N; F++) {
f o r (C = 1 ; C <= N; C++) {
MATA[F, C] = rnd.Nex t(0, 1 0 ) ;
MATB[F, C] = rnd.Nex t(0, 1 0 ) ;
/ / SALIDA MATRIZ A
Console.SetCursorPosition(C * 4 , F ) ;
Console.Write(MATA[F, C ] ) ;
/ / SALIDA MATRIZ B
Console.SetCursorPosition(C * 4 , F + 6 ) ;
Console.Write(MATB[F, C ] ) ;
}
} 148
Ing. Patricio Medina
/ / PROCESO
f o r (F = 1 ; F <= N; F++) {
f o r (C = 1 ; C <= N; C++) {
f o r (K = 1 ; K <= N; K++) {
MATC[F, C] = MATC[F, C] + (MATA[F, K] * MATB[K, C ] ) ;
}
}
}
/ / SALIDA
Console.WriteLine();
Console.WriteLine("MATRIZ RESULTANTE");
f o r (F = 1 ; F <= N; F++) {
f o r (C = 1 ; C <= N; C++) {
Console.SetCursorPosition(C * 4 , F + 1 3 ) ;
Console.Write(MATC[F, C ] ) ;
}
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}

4. GRABAR Y EJECUTAR

149
Ing. Patricio Medina
EJERCICIO PROPUESTO
Concepto:
Confeccionaremos un programa que permita crear una matriz irregular y luego imprimir la
matriz en forma completa.

1. Abrir un nuevo Proyecto


2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace M a t ri z I rre g u l a r1
{
class M a t ri z I rre g u l a r1
{
p r i v a t e i n t [ ] [ ] mat;

p u b l i c void Cargar()
{
Console.Write("Cuantas f i l a t i e n e l a m a t r i z : " ) ;
s t r i n g l i n e a = Console.ReadLine();
i n t f i l a s = int.Parse(linea);
mat = new i n t [ f i l a s ] [ ] ;
f o r ( i n t f = 0 ; f < mat.Length; f ++)
{
Console.Write("Cuantas elementos t i e n e l a f i l a " + f + " : " ) ;
l i n e a = Console.ReadLine();
i n t elementos = i n t . P a r s e ( l i n e a ) ;
m a t [ f ] = new i n t [ e l e m e n t o s ] ;
f o r ( i n t c = 0 ; c < m a t [ f ] . L e n g t h ; c++)
{
Console.Write("Ingrese componente:");
l i n e a = Console.ReadLine();
mat[f][c] = int.Parse(linea);
}
}
}
150
Ing. Patricio Medina
p u b l i c void I m p r i m i r ( )
{
f o r ( i n t f = 0 ; f < mat.Length; f ++)
{
f o r ( i n t c = 0 ; c < m a t [ f ] . L e n g t h ; c++)
{
Co ns ol e . Wri t e(ma t [ f ] [ c ] + " " ) ;
}
Console.WriteLine();
}
Console.ReadLine();
}

s t a t i c void M a i n ( s t r i n g [ ] args)
{
M a t ri z I rre g u l a r1 ma = new M a t r i z I r r e g u l a r 1 ( ) ;
ma.Cargar();
m a . I m p ri m i r();
}
}
}

4. GRABAR Y EJECUTAR

151
Ing. Patricio Medina
GENERACIÓN DEL TRÍANGULO DE PASCAL FORMA
1
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t F = 0;
i n t C = 0;
i n t N = 0;
s t r i n g cadena;
Console.Write("Cuantas F i l a s : " ) ;
cadena =Console.ReadLine();
N = int.Parse(cadena);
i n t [ , ] MAT = new i n t [ N + 1 , N + 1 ] ;
/ / PROCESO
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N; C++)
{
i f ( ( ( C == 1) | (F == C ) ) )
{
MAT[F, C] = 1 ;
}
else
{
MAT[F, C] = MAT[F - 1 ,
C] + MAT[F - 1 , C - 1 ] ;
}
}
}
/ / SALIDA
f o r (F = 1 ; F <= N; F++) 152
{
Ing. Patricio Medina
f o r (C = 1 ; C <= N; C++)
{
i f ((MAT[F, C] ! = 0 ) )
{
Console.Write("{0} " , MAT[F, C ] ) ;
}
}
Console.WriteLine();
}
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

GENERACIÓN DEL TRÍANGULO DE PASCAL FORMA


2
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1

153
Ing. Patricio Medina
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ] args)
{
i n t F = 0;
i n t C = 0;
i n t N = 0;
i n t COL = 0 ;
i n t FI = 0 ;
s t r i n g cadena;
Console.Write("Cuantas F i l a s : " ) ;
cadena= Console.ReadLine();
N = int.Parse(cadena);
i n t [ , ] MAT = new i n t [ N + 1 , N + 1 ] ;
/ / PROCESO
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N; C++)
{
i f ( ( ( C == 1) | (F == C ) ) )
{
MAT[F, C] = 1 ;
}
else
{
MAT[F, C] = MAT[F - 1 ,
C] + MAT[F - 1 , C - 1 ] ;
}
}
}
/ / SALIDA
FI = 2 ;
f o r (F =
1 ; F <= N;
F++)
{
COL =
40 -
(F *
2);
for
(C =
1; C
<= N;
C++)
{
i
f
(
(
M
A
T
[
F
,
C
] 154
!
Ing. Patricio Medina =

0
)
)
MATRIZ TRANSPUESTADE NxN
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t F = 0;
i n t C = 0;
i n t N = 0;
string
cadena;
/ / INGRESO
/ / PARA COMODIDAD GENERAMOS VALORES PARA LA MATRIZ
Console.Write("TAMAÑO DE LA MATRIZ: " ) ;
cadena =Console.ReadLine();
N = i n t . P a rs e (cadena);
i n t [ , ] MAT = new i n t [ 1 0 0 , 1 0 0 ] ; 155
Ing. Patricio Medina
i n t [ , ] MATT = new i n t [ N + 1 , N + 1 ] ;
Random rnd = new Random();
f o r (F = 1 ; F <= N; F++) {
f o r (C = 1 ; C <= N; C++) {
MAT[F, C] = rnd.Nex t(0,
100);
Console.SetCursorPosition(C * 4 , F + 1 ) ;
Console.Write(MAT[F, C ] ) ;
}
}
/ / PROCESO
f o r (F = 1 ; F <= N; F++) {
f o r (C = 1 ; C <= N; C++)
{ MATT[F, C] = MAT[C,
F];
}
}
/ / SALIDA
f o r (F = 1 ; F <= N; F++) {
f o r (C = 1 ; C <= N; C++) {
Console.SetCursorPosition(C * 4 , F + 1 0 ) ;
Console.Write(MATT[F, C ] ) ;
}
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

156
Ing. Patricio Medina
MAYORES DE CADA FILA DE UNA MATRIZ NxN EN UN
VECTOR
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t F = 0;
i n t C = 0;
i n t N = 0;
i n t MAY = 0 ;
string
cadena;
/ / INGRESO
/ / PARA COMODIDAD GENERAMOS VALORES PARA LA MATRIZ
Console.Write("TAMAÑO DE LA MATRIZ: " ) ;
cadena = Console.ReadLine();
N = int.Parse(cadena);
i n t [ , ] MAT = new i n t [ 10 0, 10 0] ;
i n t [ ] VEC = new i n t [ N + 1 ] ;
Random rnd = new Random();
f o r (F = 1 ; F <= N; F++) {
f o r (C = 1 ; C <= N;
C++) {
MAT[F, C] =
rnd.Nex t(0,
100);
Console.SetCursorPosition(C * 4 , F + 1 ) ;
Console.Write(MAT[F, C ] ) ;
}
} 157
/ / PROCESO
Ing. Patricio Medina
f o r (F = 1 ; F <= N; F++)
{ MAY = MAT[F, 1 ] ;
f o r (C = 1 ; C <= N; C++) { if
(MAT[F, C] > MAY)
MAY = MAT[F, C ] ;
}
VEC[F] = MAY;
}
/ / SALIDA
f o r (F = 1 ; F <= N; F++) {
Console.SetCursorPosition(50, F + 1 ) ;
Console.Write(VEC[F]);
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

MENORES DE CADA COLUMNA DE UNA MATRIZ NxN EN UN


VECTOR
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
158
Ing. Patricio Medina
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ] args)
{
i n t F = 0;
i n t C = 0;
i n t N = 0;
i n t MEN = 0 ;
string
cadena;
/ / INGRESO
/ / PARA COMODIDAD GENERAMOS VALORES PARA LA MATRIZ
Console.Write("TAMAÑO DE LA MATRIZ: " ) ;
cadena =Console.ReadLine();
N = i n t . P a rs e (cadena ) ;
i n t [ , ] MAT = new i n t
[ 10 0, 10 0] ;
i n t [ ] VEC = new i n t [ N + 1 ] ;
Random rnd = new Random();
f o r (F = 1 ; F <= N; F++) {
f o r (C = 1 ; C <= N; C++) { MAT[F,
C] = rnd.Nex t(0, 100);
Console.SetCursorPosition(C * 4 , F + 1 ) ;
Console.Write(MAT[F, C ] ) ;
}
}
/ / PROCESO
f o r (C = 1 ; C <= N; C++)
{ MEN = MAT[1, C ] ;
f o r (F = 1 ; F <= N; F++) { i f
((MAT[F, C] < MEN))
MEN = MAT[F, C ] ;
}
VEC[C] = MEN;
}
/ / SALIDA
f o r (C = 1 ; C <= N; C++) {
Console.SetCursorPosition(C * 4 , 1 5 ) ;
Console.Write(VEC[C]);
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

159
Ing. Patricio Medina
PROMEDIOS DE CADA COLUMNA DE UNA MATRIZ NxN EN
UN

VECTOR
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t F = 0;
i n t C = 0;
i n t N = 0;
i n t SUM = 0 ;
string
cadena; 160
Ing. Patricio Medina
/ / INGRESO
/ / PARA COMODIDAD GENERAMOS VALORES PARA LA MATRIZ
Console.Write("TAMAÑO DE LA MATRIZ: " ) ;
cadena=Console.ReadLine();
N = int.Parse(cadena);
i n t [ , ] MAT = new i n t [ N + 1 ,
N + 1];
do ubl e [ ] VEC = new double[N + 1 ] ;
Random rnd = new Random();
f o r (F = 1 ; F <= N; F++)
{
f o r (C = 1 ; C <= N; C++)
{
MAT[F, C] = rnd.Nex t(0,
100);
Console.SetCursorPosition(C * 6 , F + 1 ) ;
Console.Write(MAT[F, C ] ) ;
}
}
/ / PROCESO
f o r (C = 1 ; C <= N; C++)
{
SUM = 0 ;
f o r (F = 1 ; F <= N; F++)
{
SUM = SUM + MAT[F, C ] ;
}
VEC[C] = SUM / N;
}
/ / SALIDA
f o r (C = 1 ; C <= N; C++)
{
Console.SetCursorPosition(C * 6 , 1 5 ) ;
Co ns ol e . Wri t e( s t ri ng . Fo rmat ( " {0: ## . 0}" , VEC[C]));
}
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

161
Ing. Patricio Medina
VOTACIONES. SUMA DE CADA COLUMNA REPRESENTA A UN

CANDIDATO OBTENER EL CANDIDATO GANADOR


1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t F = 0;
i n t C = 0;
i n t N = 0;
i n t COL = 0 ;
i n t MAY = 0 ;
i n t SUM = 0 ;
string
cadena;
/ / INGRESO
/ / PARA COMODIDAD GENERAMOS VALORES PARA LA MATRIZ
Console.Write("TAMAÑO DE LA MATRIZ: " ) ;
cadena =Console.ReadLine();
N = i n t . P a rs e (cadena ) ;
i n t [ , ] MAT = new i n t [ 10 0, 10 0] ;
i n t [ ] VEC = new i n t [ N + 1 ] ;
Random rnd = new Random();
f o r (F = 1 ; F <= N; F++) {
f o r (C = 1 ; C <= N; C++)
{ MAT[F, C] = rnd.Nex t(0,
10);
Console.SetCursorPositio
n(C * 6 , F + 1 ) ;
Console.Write(MAT[F,
C]); 162
Ing. Patricio Medina }
}
/ / PROCESO
f o r (C = 1 ; C <= N; C++)
{ SUM = 0 ;
f o r (F = 1 ; F <= N; F++) {
SUM = SUM + MAT[F,
C];
}
VEC[C] = SUM;
}
MAY = VEC[1]; COL = 1 ;
f o r (C = 2 ; C <= N; C++)
{ i f (VEC[C] > MAY)
{
MAY = VEC[C];
COL = C;
}
}
/ / SALIDA
f o r (C = 1 ; C <= N; C++) {
Console.SetCursorPosition(C * 6 , 1 5 ) ;
Console.Write(VEC[C]);
}
Consol e. Wr i t eLi ne( ) ;
Consol e. Wr i t eLi ne( )
;
Console.WriteLine("NÚMERO
MAYOR ES { 0 } ESTA EN
LA COLUMNA { 1 } " , MAY,
COL);
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
}
}
4. GRABAR Y EJECUTAR

163
Ing. Patricio Medina
CUBO DE UN
NÚMERO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM = 0 ;
i n t RESUL = 0 ;
s t r i n g cadena;
Program ob =new Program();
Console.Write("DIGITE UN NÚMERO: " ) ;
cadena = Console.ReadLine();
NUM = int.Parse(cadena);
RESUL = ob .CUBO (NUM ) ;
Console.Write("EL CUBO
DE { 0 } ES: { 1 } " , NUM,
RESUL);
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();

}
p r i v a t e i n t CUBO(int AUX)
{
r e t u r n AUX * AUX * AUX;
}
}

}
164
Ing. Patricio Medina
4. GRABAR Y EJECUTAR

MAYOR DE TRES
NÚMEROS
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO

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

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
Program ob = new Program();
i n t NUM1 = 0 ;
i n t NUM2 = 0 ;
i n t NUM3 = 0 ;
s t r i n g cadena;
long RESUL = 0 ;
Console.Write("DIGITE NÚMERO 1 : " ) ;
cadena = Console.ReadLine();
NUM1 = int.Parse(cadena);
Console.Write("DIGITE NÚMERO 2 : " ) ; 165
Ing. Patricio Medina
cadena = Console.ReadLine();
NUM2 = int.Parse(cadena);
Console.Write("DIGITE NÚMERO
3: " ) ;
cadena = Console.ReadLine();
NUM3 = int.Parse(cadena);
RESUL =ob. MAYOR(NUM1, NUM2,
NUM3);
Console.Write("EL MAYOR ES: "
+ RESUL);
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
p r i v a t e i n t MAYOR(int N1, i n t N 2 , i n t N3)
{
i n t MAY ;
MAY = N1;
i f (N2 >
MAY)
{
MAY = N2;
}
i f (N3 > MAY)
{
MAY = N3;
}
r e t u r n MAY;
}

}
}

4. GRABAR Y
EJECUTAR

166
Ing. Patricio Medina
VALORABSOLUTO DE UN NÚMERO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
Program ob = new Program();
i n t NUM = 0 ;
long RESUL = 0 ;
s t r i n g cadena;
Console.Write("DIGITE UN NÚMERO: " ) ;
cadena = Console.ReadLine();
NUM = int.Parse(cadena);
RESUL = ob.MIABS(NUM);
Console.Write("VALOR
ABSOLUTO ES: " + RESUL);
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
p r i v a t e long MIABS(int AUX)
{
i f (AUX < 0 )
{
AUX = AUX * - 1 ;
}
r e t u r n AUX;
}
}
}

167
Ing. Patricio Medina
4. GRABAR Y EJECUTAR

FACTORIAL DE UN
NÚMERO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
Program ob = new Program();
i n t NUM = 0 ;
long RESUL = 0 ;
s t r i n g cadena;
Console.Write("DIGITE UN NÚMERO: " ) ;
cadena = Console.ReadLine();
NUM = int.Parse(cadena);
RESUL = ob.FACTORIAL(NUM);
Console.Write("EL FACTORIAL
DE { 0 } ES: { 1 } " , NUM,
RESUL);
Console.WriteLine(); 168
Console.Write("Pulse una Te c l a : " ) ;
Ing. Patricio Medina
Console.ReadLine();
}
p r i v a t e long FACTORIAL(int AUX)
{
long RES = 1 ;
byte K = 0 ;
f o r (K = 2 ; K
<= AUX; K++)
{
RES = RES
* K;
}
r e t u r n RES;
}
}
}

4. GRABAR Y
EJECUTAR

INVERTIR UNA
FRASE
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
169
Ing. Patricio Medina
s t a t i c void M a i n ( s t r i n g [ ] args)
{
s t r i n g NOM ;
Program ob = new Program();
Console.Write("DIGITE UNA FRASE: " ) ;
NOM = Console.ReadLine();
Console.Write("RESULTADO ES: " +
ob.INVERTIR(NOM));
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
p u b l i c s t r i n g INVERTIR(string FRASE)
{
s t r i n g AUX ;
s t r i n g cadena;
Program ob =
new Program();
i n t POS=FRASE.Length;
Console.WriteLine (POS);
AUX = " " ;
while (POS >=1)
{
cadena = ob.Mid(FRASE, POS-1);
AUX = AUX + cadena;
POS--;
}
r e t u r n AUX;
}
p u b l i c s t r i n g M i d ( s t r i n g param, i n t
startIndex)
{
r e t u r n param.Substring(startIndex,
1);
}
}
}
4. GRABAR Y EJECUTAR

170
Ing. Patricio Medina
COMPROBAR SI UN NÚMERO ES MÚLTIPLO DE
OTRO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM1 = 0 ;
i n t NUM2 = 0 ;
s t r i n g RESUL ;
s t r i n g cadena;
Program ob=new Program ( ) ;
Console.Write("DIGITE NÚMERO 1 : " ) ;
cadena = Console.ReadLine();
NUM1 = int.Parse(cadena);
Console.Write("DIGITE NÚMERO 2 : " ) ;
cadena = Console.ReadLine();
NUM2 = int.Parse(cadena);
RESUL = ob.MULTIPLO(NUM1, NUM2);
Console.WriteLine();
Console.WriteLine("{0} { 1 } DE { 2 } " ,
NUM1, RESUL, NUM2);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
p r i v a t e s t r i n g MULTIPLO(int
N1 , i n t N2 )
{
string
171
Ing. Patricio Medina
R; i n t
num;
num = N1 %
N2;
i f (num == 0)
{
R = "ES MÚLTIPLO";
}
else
{
R = "NO ES MÚLTIPLO";
}

r e t u r n R;

}
}

4. GRABAR Y EJECUTAR

NÚMERO A QUE DÍA DE LA SEMANA


CORRESPONDE
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

172
Ing. Patricio Medina
namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ] args)
{
i n t NUM = 0 ;
s t r i n g RESUL = n u l l ;
s t r i n g cadena;
Program ob=new Program ( ) ;
Console.Write("DIGITE NÚMERO : " ) ;
cadena = Console.ReadLine();
NUM = int.Parse(cadena);
RESUL = ob.DIASEMANA(NUM);
Console.WriteLine();
Console.WriteLine("RESULTADO ES: " + RESUL);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
p r i v a t e s t r i n g DIASEMANA(int DIA)
{
string R = n u l l ;
switch (DIA)
{
case 1 :
R=
"DOMING
O";
br eak;
case 2 :
R
=
"LUNE
S";
br eak;
case 3 :
R
=
"MART
ES";
br eak;
case 4 :
R
=
"MIÉR
COLES
";
br eak;
case 5 :
R
=
"JUEV
ES";
br eak;
case 6 :
R
=
"VIER
NES"; 173
Ing. Patricio Medina br eak;
case 7 :
R
=
"SÁBA
NÚMERO COMPROBAR SI ES
PRIMO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t NUM = 0 ;
s t r i n g RESUL = n u l l ;
s t r i n g cadena;
Program ob = new
Program();
Console.Write("DIGITE NÚMERO : " ) ;
cadena = Console.ReadLine();
NUM = int.Parse(cadena);
RESUL = ob.PRIMO(NUM);
Console.WriteLine();
Console.WriteLine("RESULTADO ES: " + RESUL);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine(); 174
}
Ing. Patricio Medina
p r i v a t e s t r i n g PRIMO(int N)
{
i n t K= 0;
i n t SW= 0 ;
i n t RESI =
0; K = 2;
SW= 0 ;
while ( ( ( K <
N) & (SW ==
0)))
{
RESI = N % K; i f
((RESI == 0 ) )
{
SW= 1 ;
}
else
{
K= K+ 1;
}
}
i f ((SW == 0 ) )
{
r e t u r n "PRIMO";
}
else
{
r e t u r n "NO
PRIMO";
}
}
}
}

4. GRABAR Y EJECUTAR

175
Ing. Patricio Medina
MENOR EN UN
ARREGLO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
int

K = 0 ; i n t CAN
= 0 ; i n t RESUL
= 0;
s t r i n g cadena;
Program ob =
new Program();
/ / INGRESO
Console.Write("C
UANTOS
ELEMENTOS: " ) ;
cadena =Console.ReadLine();
CAN = int.Parse(cadena); i n t [ ]
VEC = new int[CAN + 1 ] ; Random
rnd = new Random(); f o r (K = 1 ;
K <= CAN; K++)
{
VEC[K] =

rnd.Nex t(1, 100);


Console.Write(VEC[K] + " ,
");
}
Console.WriteLine(); 176
RESUL = ob.VECTORMENOR(VEC,
Ing. Patricio Medina
CAN);
Console.WriteLine();
Console.WriteLine("EL MENOR ES ES: " + RESUL);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
i n t MEN = 0 ;
i n t I = 0;
MEN =
NUEVO[1];
for ( I = 2; I
<= N; I ++)
{
i f ((NUEVO[I] < MEN))
MEN = NUEVO[I];
}
r e t u r n MEN;
}

}
}

4. GRABAR Y EJECUTAR

TRANSFORMAR NÚMERO DECIMAL A


BINARIO
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
177
Ing. Patricio Medina
class Program
{
s t a t i c void M a i n ( s t r i n g [ ] args)
{
i n t NUM1 = 0 ;
s t r i n g RESUL = n u l l ;
s t r i n g cadena;
Program ob = new Program();
Console.Write("DIGITE NÚMERO : " ) ;
cadena = Console.ReadLine();
NUM1 = int.Parse(cadena);
RESUL = ob.BINARIO(NUM1);
Console.WriteLine();
Console.WriteLine("RESULTADO ES: " + RESUL);
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
p r i v a t e s t r i n g BINARIO(int NUM)
{
i n t K= 0;
i n t AUX = 0 ;
string R =
null;
s t r i n g BIN = n u l l ;
R= "";
while ((NUM >= 2 ) )
{
AUX = NUM %
2;
R = R + AUX.ToString();
NUM = NUM / 2 ;
}
R = R + NUM.ToString();
BIN = " " ;
f o r (K = R.Length; K >=
1 ; K += - 1 )
{
BIN = BIN +
R.Substring(K-1,
1);
}
r e t u r n BIN;
}
}
}

4. GRABAR Y EJECUTAR

178
Ing. Patricio Medina
EJERCICIO PROPUESTO
Concepto:
Crear y cargar una matriz de 4 filas por 4 columnas. Imprimir la diagonal principal.
x - - -
- x - -
- - x -
- - - x
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Matriz2
{
class Matriz2
{
p r i v a t e i n t [ , ] mat;

p u b l i c void Cargar()
{
mat = new i n t [ 4 , 4 ] ;
for ( i n t f = 0; f < 4;
f ++)
{
for ( i n t c = 0; c <
4 ; c++)
{
Console.Write("Ingrese componente:");
string linea;
l i n e a = Console.ReadLine();
mat[f, c] = int.Parse(linea);
}
}
}

p u b l i c void I m pri m i rDi a gona l P ri n c i pa l ()


{ 179
Ing. Patricio Medina
f o r ( i n t k = 0 ; k < 4 ; k++)
{
Console.Write(mat[k, k ] + " " ) ;
}
Console.ReadKey();
}

s t a t i c void M a i n ( s t r i n g [ ] args)
{
Matriz2 ma = new M a t r i z 2 ( ) ;
ma.Cargar();
ma. I mpr i mi r Di agonal Pr i nci pal (
);
}
}
}

4. GRABAR Y EJECUTAR

Nota: el programa como adicional puede ser modificado para mostrar toda la matriz y comprobar el
resultado del programa.

180
Ing. Patricio Medina
OBTENER EL DÍGITO VERIFICADOR DE LA
CÉDULA
1. Abrir un nuevo Proyecto
2. Seleccione Visual Basic y Aplicación de Consola

3. CÓDIGO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
s t a t i c void M a i n ( s t r i n g [ ]
args)
{
i n t DV = 0 ;
s t r i n g MICEDU = n u l l ;
Program ob=new Program ( ) ;
Console.Write("DIGITE 9
PRIMEROS DÍGITOS DE SU
CÉDULA: " ) ;
MICEDU = Console.ReadLine();
DV = ob.ci(MICEDU);
Console.Write("EL DÍGITO
VERIFICADOR ES: " + DV);
Console.WriteLine();
Console.Write("Pulse una Te c l a : " ) ;
Console.ReadLine();
}
p u b l i c i n t c i ( s t r i n g CED)
{
i n t SUMP = 0 ;
i n t SUMI = 0 ;
i n t ST = 0 ;
i n t AUX = 0 ;
i n t P= 0;
i n t DIGITO =
0;
/ / SUMATORIA DE PARES
SUMP = 0 ; 181
SUMI = 0 ;
Ing. Patricio Medina
f o r (P = 2 ; P <=8; P +=
2)
{
SUMP = SUMP +
int.Parse(CED.Su
}
/ / SUMATORIA DE IMPARES
f o r (P = 1 ; P <= 9 ; P += 2)
{
AUX = i n t . P a rs e (CED.Substring ( P - 1 , 1 ) ) * 2 ;
i f (AUX > 9 )
AUX = AUX - 9 ;
SUMI = SUMI + AUX;
}
/ / OBTENCIÓN DE
DÍGITO ST = SUMP + SUMI;
DIGITO = 10 - (ST %
10);
i f (DIGITO == 10)
DIGITO = 0 ;
r e t u r n DIGITO;
}
}

4. GRABAR Y EJECUTAR

182
Ing. Patricio Medina

También podría gustarte