Está en la página 1de 65

UNIVERSIDAD NACIONAL DE

HUANCAVELICA
FACULTAD DE INGENIERÍA
ELECTRÓNICA-SISTEMAS
ESCUELA PROFESIONAL INGENIERÍA
ELECTRÓNICA

“AÑO DEL DIÁLOGO Y LA RECONCILIACIÓN


NACIONAL”

PROGRAMAS EN C#

ASIGNATURA: CIRCUITOS DIGITALES I


SEMESTRE: 2018 -II
DOCENTE: DR. MARQUEZ CAMRENA JAVIER
ALUMNOS: HUAIRA TAIPE EMERSON NEWTON
PROGRAMACION DIGITAL I

PAMPAS TAYACAJA -2018

pág. 2
PROGRAMACION DIGITAL I

pág. 3
PROGRAMACION DIGITAL I

INVERTIR NÚMERO DE DOS CIFRAS

CÓDIGO
using System;
using
System.Collections.Generic
; using System.Linq; using
System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int NUM, AUX, DEC, UNI;
string linea;
Console.WriteLine ("INGRESE NÚMERO DE DOS
CIFRAS :"); linea = Console.ReadLine();
NUM = int.Parse(linea);
DEC = NUM/10;
UNI = NUM % 10;
AUX = (UNI * 10) + DEC;
Console.WriteLine("NÚMERO INVERTIDO ES: " + AUX);
Console.WriteLine("Pulse una Tecla:"); Console.ReadLine();
}
}
}

GRABAR Y EJECUTAR

INVERTIR NÚMERO DE TRES CIFRAS


pág. 4
PROGRAMACION DIGITAL I

CÓDIGO
using System;
using
System.Collections.Generic
; using System.Linq; using
System.Text;
namespace ConsoleApplication1
{
class Program
{ static void Main(string[]
args)
{ int NUM, AUX, DEC,
UNI, CEN;
string linea;
Console.WriteLine ("INGRESE NÚMERO DE TRES
CIFRAS :"); linea = Console.ReadLine();
NUM = int.Parse(linea);
CEN = NUM /100;
NUM = NUM % 100;
DEC = NUM/10;
UNI = NUM % 10;
AUX = (UNI * 100) + (DEC*10) + CEN;
Console.WriteLine("NÚMERO INVERTIDO ES: " + AUX);
Console.WriteLine("Pulse una Tecla:"); Console.ReadLine();
}
}
}

GRABAR Y EJECUTAR

OPERACIONES BÁSICAS
pág. 5
PROGRAMACION DIGITAL I
CÓDIGO
using System;
using System.Collections.Generic;
using
System.Linq;
using
System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int NUM1, NUM2, RESUL;
string linea;
Console.Write("PRIMER NÚMERO :");
linea = Console.ReadLine();
NUM1 = int.Parse(linea);
Console.Write("SEGUNDO
NÚMERO :"); linea =
Console.ReadLine();
NUM2 = int.Parse(linea);
Console.WriteLine();
RESUL = NUM1 + NUM2;
Console.WriteLine("LA 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 Tecla:"); Console.ReadLine();
} }}
GRABAR Y EJECUTAR

EJERCICIO PROPUESTO

pág. 6
PROGRAMACION DIGITAL I

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


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

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

namespace Ejercicio_propuesto_1
{
class Program
{
static void Main(string[] args)
{
int NUM1, NUM2;
double RESUL;
string linea;
Console.Write("NÚMERO 1 :"); linea = Console.ReadLine();
NUM1 = int.Parse(linea);
Console.Write("NÚMERO 2 :"); linea = Console.ReadLine();
NUM2 = int.Parse(linea);
RESUL = (NUM1 + NUM2) * (NUM1 - NUM2);
Console.WriteLine();
Console.WriteLine("El resultado es : " +RESUL );
Console.ReadLine();
}
}
}
GRABAR Y EJECUTAR

MAYOR DE DOS NÚMEROS


pág. 7
PROGRAMACION DIGITAL I

CÓDIGO
using System;
using
System.Collections.Generic
; using System.Linq; using
System.Text;
namespace ConsoleApplication1
{ class
Program
{
static void Main(string[] args)
{ int
NUM1, NUM2;
string linea;
Console.Write("NÚM
ERO 1 :"); linea =
Console.ReadLine();
NUM1 = int.Parse(linea);
Console.Write("NÚMERO 2 :"); linea = Console.ReadLine();
NUM2 = int.Parse(linea);
if ((NUM1 > NUM2))
{
Console.WriteLine("{0} ES MAYOR QUE {1}", NUM1, NUM2);
}
else
{
if ((NUM1 == NUM2))
{
Console.WriteLine("{0} ES IGUAL A {1}", NUM1, NUM2);
}
else
{
Console.WriteLine("{0} ES MENOR QUE {1}", NUM1, NUM2);
}
}
Console.WriteLine();
Console.WriteLine("OTRA
MANERA"); string RESUL;
if (NUM1 > NUM2 )
{
RESUL = "MAYOR";
}
else
if (NUM1 == NUM2 )
pág. 8
PROGRAMACION DIGITAL I

{
RESUL = "IGUAL";
}
else
{
RESUL = "MENOR";
}

Console.WriteLine("{0} ES {1} QUE {2}", NUM1, RESUL, NUM2);


Console.Write("Pulse una Tecla:"); Console.ReadLine()
}

}}
GRABAR Y EJECUTAR

MAYOR DE TRES NÚMEROS


CÓDIGO
using System;
using
System.Collections.Generic
; using System.Linq; using
System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
byte MAY, MEN, NUM1, NUM2,
NUM3; string linea;
Console.Write("NÚMERO 1 :"); linea = Console.ReadLine();
NUM1 = byte.Parse(linea);
Console.Write("NÚMERO 2 :"); linea =
Console.ReadLine(); NUM2 = byte.Parse(linea);
pág. 9
PROGRAMACION DIGITAL I
Console.Write("NÚMERO 3 :"); linea = Console.ReadLine();
NUM3 = byte.Parse(linea);
MAY = NUM1; MEN = NUM1; if
((NUM2 > MAY)) MAY = NUM2; if
((NUM3 > MAY)) MAY = NUM3; if
((NUM2 > MEN)) MEN = NUM2; if
((NUM3 < MEN)) MEN = NUM3;
Console.WriteLine("MAYOR ES:" + MAY);
Console.WriteLine("MENOR ES:" + MEN);
Console.WriteLine("Pulse una Tecla:"); Console.ReadLine();
}
}
}
GRABAR Y EJECUTAR

NÚMERO INTERMEDIO
CÓDIGO
using System;
using
System.Collections.Generic
; using System.Linq; using
System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{ int NUM1,
NUM2, NUM3;
string linea;
Console.Write("PRIMER NÚMERO :"); linea = Console.ReadLine();
NUM1 = int.Parse(linea);
Console.Write("SEGUNDO NÚMERO :"); linea = Console.ReadLine();
NUM2 = int.Parse(linea);
Console.Write("TERCER NÚMERO :"); linea = Console.ReadLine();
NUM3 = int.Parse(linea);
Console.WriteLine();
pág. 10
PROGRAMACION DIGITAL I

Console.Write("EL INTERMEDIO ES: ");


if ((NUM1 > NUM2))
{
if ((NUM1 < NUM3))
{
Console.WriteLine(NUM1);
}
else {
if ((NUM2 < NUM3))
{
Console.WriteLine(NUM3);
}
else
{
Console.WriteLine(NUM2);
}
} }
else
{
if ((NUM2 < NUM3))
{
Console.WriteLine(NUM2);
}
else {
if ((NUM1 < NUM3))
{
Console.WriteLine(NUM3);
}
else
{
Console.WriteLine(NUM1);
} }}
Console.Write("Pulse una Tecla:"); Console.ReadLine();
}}}
GRABAR Y EJECUTAR

TARIFA TELEFÓNICA

pág. 11
PROGRAMACION DIGITAL I
CÓDIGO
using System;
using
System.Collections.Generic
; using System.Linq; using
System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int CANKV;
double TOT, COSKV;
COSKV = 0;
string linea;
Console.Write("Cantidad de Kilovatios :"); linea =
Console.ReadLine(); CANKV = int.Parse(linea); if ((CANKV
<= 1000)) COSKV = 0.14;
if (((CANKV > 1000) & (CANKV <= 1800))) COSKV =
0.12; if ((CANKV > 1800)) COSKV = 0.8;
TOT = CANKV * COSKV;
Console.WriteLine("A PAGAR: " + TOT);
Console.Write("Pulse una Tecla:");
Console.ReadLine(); }
}
}

GRABAR Y EJECUTAR

TRIÁNGULOS

CÓDIGO
using System;

pág. 12
PROGRAMACION DIGITAL I

using
System.Collections.Generic
; using System.Linq; using
System.Text;
namespace ConsoleApplication1
{
class Program
{ static void Main(string[]
args)
{ int LADO1,
LADO2, LADO3; string
linea;
Console.Write("DIGITE LADO 1 :"); linea = Console.ReadLine();
LADO1 = int.Parse(linea);
Console.Write("DIGITE LADO 2 :"); linea = Console.ReadLine();
LADO2 = int.Parse(linea);
Console.Write("DIGITE LADO 3 :"); linea = Console.ReadLine();
LADO3 = int.Parse(linea);
if ((LADO1 == LADO2) & (LADO2 == LADO3))
{
Console.WriteLine("TRIÁNGULO EQUILÁTERO. TODOS IGUALES");
}
else
{
if ((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 Tecla:"); Console.ReadLine();
}

}}

GRABAR Y EJECUTAR

pág. 13
PROGRAMACION DIGITAL I

DÍA DE LA SEMANA

CÓDIGO
using System;
using
System.Collections.Generic
; using System.Linq; using
System.Text; namespace
Dias_de_la_Semana
{ class
Program
{ static void Main(string[]
args)
{ int num; string linea;
Console.WriteLine();
Console.WriteLine("DIAS DE LA SEMANA");
Console.WriteLine();
Console.Write("Ingrese un numero del 1 al
7 :"); linea = Console.ReadLine(); num
= int.Parse(linea);
switch (num)
{
case 1:
Console.WriteLine();
Console.WriteLine("El numero que ingreso corresponde al dia
DOMINGO");
break;
case 2:
Console.WriteLine();
Console.WriteLine("El numero que ingreso corresponde al dia
LUNES"); break; case 3:
Console.WriteLine();
Console.WriteLine("El numero que ingreso corresponde al dia
MARTES"); break; case 4:
Console.WriteLine();

pág. 14
PROGRAMACION DIGITAL I

Console.WriteLine("El numero que ingreso corresponde al dia


MIERCOLES");
break;
case 5:
Console.WriteLine();
Console.WriteLine("El numero que ingreso corresponde al dia
JUEVES"); break; case 6:
Console.WriteLine();
Console.WriteLine("El numero que ingreso corresponde al dia
VIERNES"); break; case 7:
Console.WriteLine();
Console.WriteLine("El numero que ingreso corresponde al dia
SABADO"); break; default:
Console.WriteLine();
Console.WriteLine("El numero que ingreso esta fuera de rango");
break;
}
Console.ReadKey();
}
}
}

GRABAR Y EJECUTAR

ESTADO CIVIL

CÓDIGO
pág. 15
PROGRAMACION DIGITAL I
using System;
using
System.Collections.Generi;
using System.Linq; using
System.Text;
namespace ConsoleApplication1
{ class
Program
{
static void Main(string[] args)
{
char ECIVIL;
string linea;
Console.Write("DIGITE C,S,V,D :"); linea = Console.ReadLine();
ECIVIL = char.Parse(linea);
switch (ECIVIL)
{
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 Tecla:"); Console.ReadLine();
}

}}
GRABAR Y EJECUTAR

CALIFICACIÓN

CÓDIGO
using System;

pág. 16
PROGRAMACION DIGITAL I

using
System.Collections.Generic
; using System.Linq; using
System.Text; namespace
ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{ int
NOTA;
string linea;
Console.Write("DIGITE CALIFICACIÓN:");linea = Console.ReadLine();
NOTA= byte.Parse (linea);
switch(NOTA) { case 19:
case 20: ; Console.WriteLine("SOBRESALIENTE");
break; case 16: case 17:
case 18:;Console.WriteLine("MUY BUENA");
break; case 14: case 15:;
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(); }
}
}
GRABAR Y EJECUTAR

TABLA DE MULTIPLICAR

CÓDIGO

pág. 17
PROGRAMACION DIGITAL I
using System;
using
System.Collections.Generic
; using System.Linq; using
System.Text;
namespace TABLA_DE_MULTIPLICAR
{
class Program
{
static void Main(string[] args)
{ byte
NUM, I; int
RESUL;
string linea;
Console.Write("DIGITE NÚMERO:"); linea =
Console.ReadLine(); NUM = byte.Parse(linea); for
(I = 1; I <= 12; I++)
{
RESUL = NUM * I;
Console.WriteLine("{0} * {1} = {2}", NUM, I, RESUL);
}
Console.Write("Pulse una Tecla:"); Console.ReadLine();
}
}
}
GRABAR Y EJECUTAR

SUMA DE N NÚMEROS PARES E IMPARES

CÓDIGO
using System;

pág. 18
PROGRAMACION DIGITAL I

using
System.Collections.Generic
; using System.Linq; using
System.Text;
namespace SUMA_DE_N_NÚMEROS_PARES_E_IMPARES
{
class
Program {
static void Main(string[] args)
{ byte
NUM, I; int
SUMP = 0;
int SUMI = 0;
string linea;
Console.Write("NÚMERO MÁXIMO: "); linea =
Console.ReadLine(); NUM = byte.Parse(linea); for (I
= 1; I <= NUM; I += 2)
{
SUMP = SUMP + I;
}
for (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 Tecla:"); Console.ReadLine();
}
}
}
GRABAR Y EJECUTAR

TABLAS DE MULTIPLICAR

CÓDIGO
pág. 19
PROGRAMACION DIGITAL I
using System;
using
System.Collections.Generic
; using System.Linq; using
System.Text;
namespace TABLAS_DE_MULTIPLICAR
{
class Program
{
static void Main(string[] args)
{ int NUM,
RESUL, T, I; string
linea;
Console.Write("CUANTAS TABLAS: "); linea =
Console.ReadLine(); NUM = int.Parse(linea); for (T =
1; T <= NUM; T++)
{ for (I = 10; I >=
1; I--)
{
RESUL = T * I;
Console.WriteLine("{0} * {1} = {2}", T, I, RESUL);
}
Console.Write("Pulse una Tecla:"); Console.ReadLine();
}
}
}
}

GRABAR Y EJECUTAR

SUMA DE NÚMEROS

CÓDIGO
using System;

pág. 20
PROGRAMACION DIGITAL I

using
System.Collections.Generic
; using System.Linq; using
System.Text; namespace
SUMA_DE_N_NÚMEROS
{
class Program
{
static void Main(string[] args)
{ byte
CAN, K; int
NUM; int
SUM = 0;
string linea;
Console.Write("LÍMITE:"); linea =
Console.ReadLine(); CAN = byte.Parse(linea);
for (K = 1; K <= CAN; K++)
{
Console.Write("DIGITE UN NÚMERO:"); linea = Console.ReadLine();
NUM=int.Parse (linea);
SUM += NUM;
}
Console.WriteLine("SUMA TOTAL ES : " + SUM);
Console.WriteLine("MEDIA ARITMÉTICA: " + SUM / CAN);
Console.Write("Pulse una Tecla:");
Console.ReadLine(); }
}
}
GRABAR Y EJECUTAR

SIMULACIÓN DE UN RELOJ DIGITAL


CÓDIGO
using System;

pág. 21
PROGRAMACION DIGITAL I
using
System.Collections.Generic
; using System.Linq; using
System.Text;
namespace SIMULACIÓN_DE_UN_RELOJ_DIGITAL
{
class Program
{
static void Main(string[] args)
{
byte H, M, S;
Console.SetCursorPosition(15, 2);
Console.Write("SIMULACIÓN DE UN RELOJ
DIGITAL"); for (H = 0; H <= 24; H++)
{
for (M = 0; M <= 59; M++)
{
for (S = 0; S <= 59; S++)
{
Console.SetCursorPosition(20, 10);
Console.Write("{0} : {1} : {2}", H, M, S);
}
}
}
Console.SetCursorPosition(25, 15);
Console.Write("Pulse una Tecla:"); Console.ReadLine();
}
}
}
GRABAR Y EJECUTAR

FACTORIAL DE UN NÚMERO
CÓDIGO
using System;
using
System.Collections.Generic

pág. 22
PROGRAMACION DIGITAL I

; using System.Linq; using


System.Text;
namespace FACTORIAL_DE_UN_NÚMERO
{ class
Program
{
static void Main(string[] args)
{
byte NUM, K;
long RESUL = 1;
string linea;
Console.Write("DIGITE UN NÚMERO: "); linea =
Console.ReadLine(); NUM = byte.Parse(linea); for (K =
2; K <= NUM; K++)
{
RESUL = RESUL * K;
}
Console.WriteLine("EL FACTORIAL ES: " + RESUL);
Console.Write("Pulse una Tecla:"); Console.ReadLine();
} }}
GRABAR Y EJECUTAR

COMPROBAR SI ES NÚMERO PRIMO

CÓDIGO
using System;
using
System.Collections.Generic
; using System.Linq; using
System.Text;
namespace Comprobar_si_es_Numero_Primo
{
class Program
{
static void Main(string[] args)

pág. 23
PROGRAMACION DIGITAL I
{ int n, x, sw,
resi; string linea;
x = 2; sw = 0;
Console.WriteLine("NUMERO PRIMO");
Console.WriteLine();
Console.Write("Ingrese el
numero:"); linea =
Console.ReadLine(); n=
int.Parse(linea); while (x < n && sw
== 0)
{
resi = n % x;
if (resi == 0)
{
sw = 1; }
else {
x = x + 1;
}
}
if (sw == 0)
{
Console.WriteLine();
Console.WriteLine("El numero es PRIMO");
}
else
{
Console.WriteLine();
Console.WriteLine("El numero no es PRIMO");
}
Console.ReadKey();
}
}}
GRABAR Y EJECUTAR

FACTORES PRIMOS DE UN NÚMERO

CÓDIGO

pág. 24
PROGRAMACION DIGITAL I

using System;
using
System.Collections.Generic
; using System.Linq; using
System.Text;
namespace FACTORES_PRIMOS_DE_UN_NÚMERO
{
class
Program {
static void Main(string[] args)
{ int NUM,
RESI, K; string
linea;
Console.Write("NÚMERO: "); linea = Console.ReadLine();
NUM=
int.Parse(linea); K=
2; while ((NUM != 1))
{
RESI = NUM % K;
if ((RESI == 0))
{
Console.WriteLine(K);
NUM = NUM / K;
}
else
{
K = K + 1;
}
}
Console.Write("Pulse una Tecla:"); Console.ReadLine();
}
}
}
GRABAR Y EJECUTAR

pág. 25
PROGRAMACION DIGITAL I

C#
EN WINDWONS
FORMS

pág. 26
PROGRAMACION DIGITAL I

CALCULADORA

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplicationButton4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button0_Click(object sender, EventArgs e)
{
if (label1.Text.Length < 12)
{
label1.Text = label1.Text + button0.Text;
}
}
private void button1_Click(object sender, EventArgs e)
{
if (label1.Text.Length < 12)
{
label1.Text = label1.Text + button1.Text;
}
}
pág. 27
PROGRAMACION DIGITAL I

private void button2_Click(object sender, EventArgs e)


{
if (label1.Text.Length < 12)
{
label1.Text = label1.Text + button2.Text;
}
}
private void button3_Click(object sender, EventArgs e)
{
if (label1.Text.Length < 12)
{
label1.Text = label1.Text + button3.Text;
}
}
private void button4_Click(object sender, EventArgs e)
{
if (label1.Text.Length < 12)
{
label1.Text = label1.Text + button4.Text;
}
}

private void button5_Click(object sender, EventArgs e)


{
if (label1.Text.Length < 12)
{
label1.Text = label1.Text + button5.Text;
}
}

private void button6_Click(object sender, EventArgs e)


{
if (label1.Text.Length < 12)
{
label1.Text = label1.Text + button6.Text;
}
}

private void button7_Click(object sender, EventArgs e)


{
if (label1.Text.Length < 12)
{
label1.Text = label1.Text + button7.Text;
}
}

pág. 28
PROGRAMACION DIGITAL I

private void button8_Click(object sender, EventArgs e)


{
if (label1.Text.Length < 12)
{
label1.Text = label1.Text + button8.Text;
}
}
private void button9_Click(object sender, EventArgs e)
{
if (label1.Text.Length < 12)
{
label1.Text = label1.Text + button8.Text;
}
}
}
}

SUMA DE DOS NUMEROS

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplicationTextBox1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
int valor1 = int.Parse(textBox1.Text);
pág. 29
PROGRAMACION DIGITAL I
int valor2 = int.Parse(textBox2.Text);
int suma = valor1 + valor2;
label4.Text = suma.ToString();
}
}
}
NUMERO DE USUARIO Y CONTRASEÑA

Solicitar que se ingrese una clave. Si se ingresa la cadena "abc123" mostrar un mensaje de
clave correcta en caso contrario mostrar clave incorrecta.Utilizar un control de tipo TextBox
para el ingreso de la clave y una Label para mostrar el resultado al presionar un botón.

CODIGO
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplicationTextBox2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "abc123")
{
label2.Text = "Clave correcta";
}
else
{
label2.Text = "Clave incorrecta";
}
pág. 30
PROGRAMACION DIGITAL I

}
}
}

CONFIGURAR ANCHO Y ALTO


Confeccionar un programa que muestre 3 objetos de la clase RadioButton que permitan
configurar el ancho y alto del Form. Cuando se presione un botón actualizar el ancho y alto.

CODIGO:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplicationRadioButton1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
if (radioButton1.Checked == true)
{
Width = 640;
Height = 480;
pág. 31
PROGRAMACION DIGITAL I
}
else
{
if (radioButton2.Checked == true)
{
Width = 800;
Height = 600;
}
else
{
if (radioButton3.Checked == true)
{
Width = 1024;
Height = 768;
}
}
}
}
}
}
if (radioButton1.Checked == true)
{
Width = 640;
Height = 480;
}
else
{
if (radioButton2.Checked == true)
{
Width = 800;
Height = 600;
}
else
{
if (radioButton3.Checked == true)
{
Width = 1024;
Height = 768;
}
}
}

pág. 32
PROGRAMACION DIGITAL I

MENSAJE
Disponer un control Label que muestre el siguiente mensaje: "Esta de acuerdo con las
normas del servicio?", luego un CheckBox y finalmente un objeto de tipo Button desactivo
Cuando se tilde el CheckBox debemos activar el botón

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplicationCheckBox2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (checkBox1.Checked == true)
{
button1.Enabled = true;
}
else
{
button1.Enabled = false;
}
}
}
}

pág. 33
PROGRAMACION DIGITAL I
MUESTRA OBJETOS

Confeccionar un programa que muestre 3 objetos de la clase CheckBox con etiquetas de


tres idiomas. Cuando se presiona un botón mostrar en la barra de títulos del Form todos los
CheckBox seleccionados hasta el momento.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplicationCheckBox1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button1_Click(object sender, EventArgs e)


{
Text = "";
if (checkBox1.Checked == true)
{
Text = Text + "(Inglés)";
}
if (checkBox2.Checked == true)
{
Text = Text + "(Francés)";
}
if (checkBox3.Checked == true)

pág. 34
PROGRAMACION DIGITAL I

{
Text = Text + "(Alemán)";
}
}
}
}
CALIFICACIONES
Se tiene un conjunto de calificaciones de un grupo de “n” alumnos, realizar un algoritmo
para calcular la calificación media y la calificación más baja de dicho grupo.

CODIGO
Private void btncalcular_Click(object sender, EventArgse)
{
//Declaración de variables
Int numalumnos;
Double nota, sumanotas, notabaja, promedio;
if(txtnumero.Text!="")
{
//Entrada de datos
numalumnos =Convert.ToInt32(txtnumero.Text);
//Inicializar las variables
sumanotas = 0.0;
notabaja = 20.0;

for(int i=1;i<=numalumnos;i=i+1)
{
nota =Convert.ToDouble(Microsoft.VisualBasic.Interaction.InputBox("Ingrese
nota del alumno "+i,"Promedio Notas","16",100,100));
sumanotas = sumanotas + nota;
if(nota<notabaja)
{
notabaja = nota;
}
}
promedio = sumanotas / numalumnos;
//Salida de Información
pág. 35
PROGRAMACION DIGITAL I
txtpromedio.Text = Convert.ToString(promedio);
txtnotabaja.Text = Convert.ToString(notabaja);

}
else
{
MessageBox.Show("Ingrese un número válido", "Promedio
Notas",MessageBoxButtons.OK, MessageBoxIcon.Error);
}
private void btnnuevo_Click(object sender, EventArgs e)
{
txtnumero.Clear();
txtnotabaja.Clear();
txtpromedio.Clear();

private void btnsalir_Click(object sender, EventArgs e)


{
Close();

}
CAPITAL Y TASA DE INTERES

Crea una aplicación sencilla que dado el capital y la tasa de interés calcule el interés
conseguido y el capital final. La fórmula para el cálculo del interés es I=(C*t)/100siendo C el
capital inicial y r la tasa de interés nominal anual en tanto por ciento. El capital acumulado
será el capital inicial más el interés.

Decimal cap, tp, res;


String formato = "{0:#,###,###,##0.00}";
try
{
cap = Convert.ToDecimal(Capital.Text);
tp = Convert.ToDecimal(TpInterés.Text);
}
catch (FormatException exc)
{
cap = 0; tp = 0;
}

// Cálculos de los resultados


res = Convert.ToDecimal(cap * tp / 100);
InterésPro.Text = String.Format(formato, res);
res += cap;
CapitalAc.Text = String.Format(formato, res);

pág. 36
PROGRAMACION DIGITAL I

FACTORIAL DE UN NUMERO

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Threading.Tasks;

using System.Windows.Forms;

namespace Factorial_E_Repetitivas
{
public partial class Form1 : Form
{
public Form1()
pág. 37
PROGRAMACION DIGITAL I
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button2_Click(object sender, EventArgs e)
{
int n, f = 1;
n = int.Parse(textBox1.Text);
for (int i=1; i<= n; i++)
{
f *= i;
textBox2.Text = f.ToString();
}
}
private void button3_Click(object sender, EventArgs e)
{
int n, f = 1, i = 1;
n = int.Parse(textBox1.Text);
while (i <= n)
{
f *= i;
i++;
textBox3.Text = f.ToString();
}
}
private void button4_Click(object sender, EventArgs e)
{
int n, f = 1, i = 1;
n = int.Parse(textBox1.Text);
do
{
f *= i;
i++;
}
while
(i <= n);
textBox4.Text = f.ToString();
}
}

DEVUELVE NUMERO A LETRA

pág. 38
PROGRAMACION DIGITAL I

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace numero4
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int numero;
string letra
private void textBox1_TextChanged(object sender, EventArgs e)
{
numero = int.Parse(textBox1.Text);
}

private void button2_Click(object sender, EventArgs e)


{
Application.Exit();
}

NUMERO PRIMO

pág. 39
PROGRAMACION DIGITAL I

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace numero5
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

//Variables
int numeroentrada, i;
bool flag;
string respuesta = "";

//Entrada

private void textBox1_TextChanged(object sender, EventArgs e)


{
numeroentrada = int.Parse(textBox1.Text);
}

// Proceso y Salida

private void button1_Click(object sender, EventArgs e)


{

pág. 40
PROGRAMACION DIGITAL I

flag = true;
i = 2;
while (i <= numeroentrada / 2)
{
if (numeroentrada % i == 0)
{
flag = false;
break;
}
i++;
}
if (flag)
respuesta = "ES PRIMO";
else
respuesta = "NO ES PRIMO";

textBox2.Text = respuesta;
}

CUENTA LA CANTIDAD DE CARACTERES

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace numero7
{
public partial class Form1 : Form
{
public Form1()
{
pág. 41
PROGRAMACION DIGITAL I
InitializeComponent();
}
//Variables
string texto;
int cantidad;
//Entrada
private void textBox1_TextChanged(object sender, EventArgs e)
{
texto = entrada.Text;
}
ORDENACION POR INTERCAMBIOS

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace numero11
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

//Variables
int tmp, i, j, LI, LS;

//Arreglos
int[] n = new int[4];

private void button2_Click(object sender, EventArgs e)

pág. 42
PROGRAMACION DIGITAL I

{
Application.Exit();
}
//Entrada
private void textBox1_TextChanged(object sender, EventArgs e)
{
n[0] = int.Parse(textBox1.Text);
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
n[1] = int.Parse(textBox2.Text);
}
private void textBox3_TextChanged(object sender, EventArgs e)
{
n[2] = int.Parse(textBox3.Text);
}
private void textBox4_TextChanged(object sender, EventArgs e)
{
n[3] = int.Parse(textBox4.Text);
}

RECONOCIMIENTO DE VOZ

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Speech.Recognition; // Para el reconocimiento de voz

pág. 43
PROGRAMACION DIGITAL I
namespace Reconocimiento_de_voz_1
{
public partial class Form1 : Form
{

// Inicializamos motor de reconocimiento.


SpeechRecognitionEngine reconocimiento_de_voz = new SpeechRecognitionEngine();

string palabras;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e) //Boton escuchar. Configuración del
reconocimiento
{
//Inicia la escucha con el dispositivo de entrada de audio predeterminado
reconocimiento_de_voz.SetInputToDefaultAudioDevice(); // Usaremos el microfono
predeterminado del sistema
reconocimiento_de_voz.LoadGrammar(new DictationGrammar()); //Carga la gramatica de
Windows
reconocimiento_de_voz.SpeechRecognized += te_escucho; // Controlador de eventos. Se
ejecutara al reconocer
reconocimiento_de_voz.RecognizeAsync(RecognizeMode.Multiple); //Iniciamos
reconocimiento
label1.Text = "Te estoy escuchando cuentame: ";
}
void te_escucho(object sender, SpeechRecognizedEventArgs e)
{
palabras = e.Result.Text; // La variable palabras del tipo string toma las palabras
reconocidas.
textBox1.Text = palabras; // Muestra las palabras reconocidas en el textbox
}
private void button3_Click(object sender, EventArgs e) // Boton detener escucha
{
reconocimiento_de_voz.RecognizeAsyncStop(); //Detiene la escucha
textBox1.Clear(); //limpia el textbox
}
private void button2_Click(object sender, EventArgs e) // Boton Salir
{
Application.Exit();
}
}
}
TABLA DE MULTIPLICAR

pág. 44
PROGRAMACION DIGITAL I

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TablaMultiplicar
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

//Variables
int numero;

private void button2_Click(object sender, EventArgs e)


{
numero = Convert.ToInt32(textBox1.Text);
while (numero <= 0)
{
MessageBox.Show("Superior a 0 por favor");
return;
}
for (int i = 1; i <= numero; i++)
{
textBox2.Text += " "+"\r\n";

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


pág. 45
PROGRAMACION DIGITAL I
{
textBox2.AppendText((i * j).ToString() + "\t");
}
}
}

NUMEROS ROMANOS

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace NumerosRomanos_Forms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int numeroentrada;
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
int Miles, Centenas, Decenas, Unidades, RestoMiles, RestoCentenas,

pág. 46
PROGRAMACION DIGITAL I

RestoDecenas, N;
N = numeroentrada;
Miles = N / 1000;
RestoMiles = N % 1000;
Centenas = RestoMiles / 100;
RestoCentenas = RestoMiles % 100;
Decenas = RestoCentenas / 10;
RestoDecenas = RestoCentenas % 10;
Unidades = RestoDecenas;
switch (Miles)
{
case 1: textBox2.Text += "M"; break;
case 2: textBox2.Text += "MM"; break;
case 3: textBox2.Text += "MMM"; break;
}
switch (Centenas)
{
case 1: textBox2.Text += "C"; break;
case 2: textBox2.Text += "CC"; break;
case 3: textBox2.Text += "CCC"; break;
case 4: textBox2.Text += "CD"; break;
case 5: textBox2.Text += "D"; break;
case 6: textBox2.Text += "DC"; break;
case 7: textBox2.Text += "DCC"; break;
case 8: textBox2.Text += "DCCC"; break;
case 9: textBox2.Text += "CM"; break;
}
MAXIMO COMUN DIVISOR

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;

pág. 47
PROGRAMACION DIGITAL I
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MCD_I_Forms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
int numero1, numero2, a, b, resultado;

private void button2_Click(object sender, EventArgs e)


{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
//Algoritmo de Euclides
//Seleccionamos el mayor y el menor para asignarlos
//a las variables a y b respectivamente
numero1 = int.Parse(textBox1.Text);
numero2 = int.Parse(textBox2.Text);
a = Math.Max(numero1, numero2);
b = Math.Min(numero1, numero2);
do //ciclo para las iteraciones
{
resultado = b; // Guardamos el divisor en el resultado
b = a % b; //Guardamos el resto en el divisor
a = resultado; //El divisor para al dividendo
}
while
(b != 0);
textBox3.Text = resultado.ToString();
}
}
}

MAQUINA DE ESTADOS FINITOS

pág. 48
PROGRAMACION DIGITAL I

using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace MEF
{

public class Form1 : Form


{
private MainMenu mainMenu1;
private MenuItem menuItem1;
private MenuItem mnuSalir;
private MenuItem menuItem3;
private MenuItem mnuInicio;
private MenuItem mnuParo;
private Timer timer1;
private IContainer components;
// Creamos un objeto para la maquina de estados finitos
private CMaquina maquina = new CMaquina();

// Objetos necesarios
public S_objeto[] ListaObjetos = new S_objeto[10];
public S_objeto MiBateria;

public Form1()
{ InitializeComponent();
Random random = new Random();
// Recorremos todos los objetos
for (int n = 0; n < 10; n++)
{
// Colocamos las coordenadas
ListaObjetos[n].x = random.Next(0, 639);
ListaObjetos[n].y = random.Next(0, 479);
// Lo indicamos activo
ListaObjetos[n].activo = true;
}

pág. 49
PROGRAMACION DIGITAL I
// Colocamos la bateria
MiBateria.x = random.Next(0, 639);
MiBateria.y = random.Next(0, 479);
MiBateria.activo = true;
maquina.Inicializa(ref ListaObjetos, MiBateria);
}

protected override void Dispose(bool disposing)


{
if (disposing)
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose(disposing);
}
static void Main()
{
Application.Run(new Form1());
}
private void mnuSalir_Click(object sender, System.EventArgs e)
{
// Cerramos la ventana y finalizamos la aplicacion
this.Close();
}
private void mnuInicio_Click(object sender, System.EventArgs e)
{
timer1.Enabled = true;
}
private void mnuParo_Click(object sender, System.EventArgs e)
{
timer1.Enabled = false;
}
private void timer1_Tick(object sender, System.EventArgs e)
{
maquina.Control();
this.Invalidate();
}
private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
// Creamos la fuente y la brocha para el texto
Font fuente = new Font("Arial", 16);
SolidBrush brocha = new SolidBrush(Color.Black);
// Dibujamos el robot
if (maquina.EstadoM == (int)CMaquina.estados.MUERTO)

pág. 50
PROGRAMACION DIGITAL I

e.Graphics.DrawRectangle(Pens.Black, maquina.CoordX - 4, maquina.CoordY -


4, 20, 20);
else
e.Graphics.DrawRectangle(Pens.Green, maquina.CoordX - 4, maquina.CoordY -
4, 20, 20);

// Dibujamos los objetos


for (int n = 0; n < 10; n++)
if (ListaObjetos[n].activo == true)
e.Graphics.DrawRectangle(Pens.Indigo, ListaObjetos[n].x - 4, ListaObjetos[n].y
- 4, 20, 20);
// Dibujamos la bateria
e.Graphics.DrawRectangle(Pens.IndianRed, MiBateria.x - 4, MiBateria.y - 4, 20, 20);

e.Graphics.DrawString("Estado -> " + maquina.EstadoM.ToString(), fuente, brocha,


10, 10);

}
}
}
FACTORES PRIMOS

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace FactoresPrimosNumero_Forms

pág. 51
PROGRAMACION DIGITAL I
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button2_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void button1_Click(object sender, EventArgs e)
{
int numero, resi, k;
string cadena = textBox2.Text;
numero = int.Parse(textBox1.Text);
k = 2;
if (!int.TryParse(textBox1.Text, out numero)) numero = -1;
if (numero < 2)
{
MessageBox.Show("Numeros negativos NO. \r\n Superiores a 2 por favor");
textBox1.Clear();
return;
}
while ((numero != 1))
{
resi = numero % k;
if ((resi == 0))
{
cadena += (k.ToString() + " x ");
textBox2.Text = cadena.Remove(cadena.Length - 2);
numero = numero / k;
}
else
{
k = k + 1;
}
}

PROBABILIDAD POLINOMIAL

pág. 52
PROGRAMACION DIGITAL I

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ProbabilidadBinomial_I
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
Application.Exit();
}
private static long Factorial(long x)
{
if (x <= 1)
return 1;
else
return x * Factorial(x - 1);
}

private static long Combination(long a, long b)


{
if (a <= 1)

pág. 53
PROGRAMACION DIGITAL I
return 1;

return Factorial(a) / (Factorial(b) * Factorial(a - b));


}
private double ProbabilidadBinomial (int ensayos, int aciertos, double probabilidad)
{
double fallos = 1 - probabilidad;
double c = Combination(ensayos, aciertos);
double px = Math.Pow(probabilidad, aciertos);
double qnx = Math.Pow(fallos, ensayos - aciertos);
return c * px * qnx;
}
DIA DEL AÑO

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OrdinalFecha_Forms
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)

pág. 54
PROGRAMACION DIGITAL I

{
Application.Exit();
}

private void button1_Click(object sender, EventArgs e)


{
int dia, mes, año;

dia = int.Parse(textBox1.Text);
mes = int.Parse(textBox2.Text);
año = int.Parse(textBox3.Text);

if (fechacorrecta(dia, mes, año) == 1)


MostrarOrdinal(diadelaño(dia, mes, año));
else
MessageBox.Show("Fecha Incorrecta");
}

int bisiesto(int año)


{
if ((año % 4 == 0) && (año % 100 != 0) || (año % 400 == 0))
return 1;
else
return 0;
}
int diasdelmes(int mes, int a)
{
int Numerodias = 0;
switch (mes)
{
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12: Numerodias = 31; break;
case 2:
if (bisiesto(a) == 1)
Numerodias = 29;
else
Numerodias = 28;
break;
case 4:
case 6:
case 9:

pág. 55
PROGRAMACION DIGITAL I
case 11: Numerodias = 30; break;

}
return Numerodias;
}

TRIANGULO DE PASCAL

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace TrianguloPascal_III
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)


{
Application.Exit();
}
//Variables

pág. 56
PROGRAMACION DIGITAL I

int numero;

private void button1_Click(object sender, EventArgs e)


{
for (int y = 0; y < numero; y++)
{
int c = 1;
for (int q = 0; q < numero - y; q++)
{
textBox2.Text += " ";
}
for (int x = 0; x <= y; x++)
{
textBox2.AppendText(c.ToString());
textBox2.Text += " " + "\n";
c = c * (y - x) / (x + 1);
}
textBox2.Text += " \r\n";
}
}

pág. 57
PROGRAMACION DIGITAL I

PROGRAMAS EN
LABVIEW

pág. 58
PROGRAMACION DIGITAL I

SEMAFORO

SUMA Y RESTA

pág. 59
PROGRAMACION DIGITAL I

DISPLAY ANODO Y CATODO

COMPUERTAS LOGICAS AND, OR, NOT Y XOR


pág. 60
PROGRAMACION DIGITAL I

SEÑAL ANALOGICA PWM


pág. 61
PROGRAMACION DIGITAL I

MEDICION DE UN TERMOMETRO

pág. 62
PROGRAMACION DIGITAL I

ENCENDIDO DE FOCOS

FACTORIAL

pág. 63
PROGRAMACION DIGITAL I

AREA DE UN CIRCULO

SIMULACION DE UN TANQUE

pág. 64
PROGRAMACION DIGITAL I

CUATRO SEMAFOROS

pág. 65

También podría gustarte