Documentos de Académico
Documentos de Profesional
Documentos de Cultura
HUANCAVELICA
FACULTAD DE INGENIERÍA
ELECTRÓNICA-SISTEMAS
ESCUELA PROFESIONAL INGENIERÍA
ELECTRÓNICA
PROGRAMAS EN C#
pág. 2
PROGRAMACION DIGITAL I
pág. 3
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;
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
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
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
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";
}
}}
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
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
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
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
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
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
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
pág. 28
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.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
}
}
}
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();
}
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
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();
}
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();
}
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.
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();
}
}
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);
}
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
// Proceso y Salida
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;
}
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];
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
{
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;
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;
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
{
// 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);
}
pág. 50
PROGRAMACION DIGITAL I
}
}
}
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);
}
pág. 53
PROGRAMACION DIGITAL I
return 1;
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();
}
pág. 54
PROGRAMACION DIGITAL I
{
Application.Exit();
}
dia = int.Parse(textBox1.Text);
mes = int.Parse(textBox2.Text);
año = int.Parse(textBox3.Text);
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();
}
pág. 56
PROGRAMACION DIGITAL I
int numero;
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
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