0% found this document useful (0 votes)
35 views18 pages

Consola C#

Download as pdf or txt
Download as pdf or txt
Download as pdf or txt
You are on page 1/ 18

Estos son unos pequeos programas de ejemplo en la programacin de C# espero que les sirva.

Pirmide
using using using using System; System.Collections.Generic; System.Text; System.Runtime.InteropServices;

namespace ConsoleApplication1 { class Program { [DllImport("msvcrt")] static extern int _getch(); static void Main(string[] args) { string text = ""; for (int i = 1; i < 22; i++) { text = ""; for (int j = 1; j < i; j++) { text += (Convert.ToString(j)+" "); } Console.WriteLine(text); Console.Write("\n"); } _getch(); } } }

Examen
FORMA 1
using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Text; System.Windows.Forms;

namespace EXAMEN_LED { public partial class Form1 : Form { public static String nombre, rfc, domicilio, telefono, ciudad; Form forma2 = new Form2(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { MessageBox.Show("ingresar datos", "informacion", MessageBoxButtons.OK, MessageBoxIcon.Information); } private void button1_Click(object sender, EventArgs e) { nombre = textBox1.Text; rfc = textBox2.Text; domicilio = textBox3.Text; telefono = textBox4.Text;

ciudad = textBox5.Text; forma2.Show(); } private void button2_Click(object sender, EventArgs e) { this.Close(); } } }

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

namespace EXAMEN_LED { public partial class Form2 : Form

{ static public float suma = 0; Form forma3 = new Form3(); public Form2() { InitializeComponent(); } private void Form2_Load(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { float solda = float.Parse(textBox1.Text); float clavos = float.Parse(textBox2.Text); float pintura = float.Parse(textBox3.Text); float brocha = float.Parse(textBox4.Text); suma = solda + clavos + pintura + brocha; forma3.Show(); } private void button2_Click(object sender, EventArgs e) { this.Close(); } } }

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

namespace EXAMEN_LED { public partial class Form3 : Form { String nombre, rfc, domicilio, telefono, ciudad; //Form forma_1 = new Form1(); //Form Forma_2 = new Form2(); float ivasuma = 0; //float inicial = Form2.suma;

public Form3() { InitializeComponent(); } private float iva15(float iva) { //Metodo pra hacer el calculo de porsentage 15% float resul = 0; resul = iva / 100; iva = resul * 15; return iva; } private void Form3_Load(object sender, EventArgs e) { label2.Text = Form1.nombre; label6.Text = Form1.rfc; label7.Text = Form1.domicilio; label8.Text = Form1.telefono; label9.Text = Form1.ciudad;

//imprimir suma de precios en textbox con convercion de float a String. textBox1.Text = Convert.ToString(Form2.suma); //llamo la metodo de iva para sacar iva ivasuma = iva15(Form2.suma); //imprimo iva y lo convierto a string pra imprimirlo

textBox2.Text = Convert.ToString(ivasuma); //suma de iva y precios ivasuma = ivasuma + Form2.suma; //imprimir total textBox3.Text = Convert.ToString(ivasuma); } private void button1_Click(object sender, EventArgs e) { this.Close(); } } }

HORA EXTRA: EN CONSOLA


using using using using System; System.Collections.Generic; System.Text; System.Runtime.InteropServices;

namespace Hora_x { class Program { [DllImport("msvcrt")] static extern int _getch(); static void Main(string[] args) { string A, B; int num1, num2, suma;

System.Console.WriteLine("_______________________________________________ _"); System.Console.Write("Ingrese Dias Trabajados : "); A= System.Console.ReadLine(); Console.Write("\n"); System.Console.WriteLine("_______________________________________________ _"); System.Console.Write("Ingrese Horas Extras Trabajadas : "); B = System.Console.ReadLine();

System.Console.WriteLine("_______________________________________________ _"); System.Console.WriteLine("pago por dia 52 pesos"); System.Console.WriteLine("pago por hora 5 pesos"); System.Console.WriteLine("pago por hora extra 11 pesos"); System.Console.WriteLine("_______________________________________________ _"); num1 = Int32.Parse(A)*(52); num2 = Int32.Parse(B) *(11);

suma = num1 + num2; Console.Write("\n"); Console.Write("\n"); Console.Write("\n"); Console.Write("\n"); System.Console.WriteLine("Dias Trabajados : " + A + " Dias"); Console.Write("\n"); System.Console.WriteLine("Horas Extras Trabajadas : " + B + " Horas Extras"); Console.Write("\n"); System.Console.WriteLine("Total en Dias : " + num1 + " Pesos"); Console.Write("\n"); System.Console.WriteLine("Total en Horas Extras : " + num2 + " Pesos"); Console.Write("\n"); System.Console.WriteLine("_______________________________________________ _"); Console.Write("\n"); System.Console.WriteLine("El Pago Total de Dias mas Horas Extras : " + suma + " Pesos"); Console.Write("\n"); Console.Write("\n"); Console.Write("\n");

_getch(); } } }

MUESTRA SI ES POSITIVO O NEGATIVO

using using using using

System; System.Collections.Generic; System.Text; System.Runtime.InteropServices;

namespace ConsoleApplication2 { class Program { [DllImport("msvcrt")] static extern int _getch(); static void Main(string[] args) { double d; Console.WriteLine("Introduce un numero :"); d = Double.Parse(Console.ReadLine()); if (d > 0) { Console.WriteLine("El numero {0} es positivo", d); } else { Console.WriteLine("El numero {0} es negativo", d); } _getch(); } } }

MOSTRAR EN UN MENSAJE
MessageBox.Show ("Nombre : " + textBox1.Text + "Apellido : " + textBox2.Text + "Mail : " + textBox3.Text + "ID : " + textBox4.Text);

SUMA CONSOLA
using using using using System; System.Collections.Generic; System.Text; System.Runtime.InteropServices;

namespace suma { class sumadosnumeros { [DllImport("msvcrt")] static extern int _getch(); public static void Main(string[] args) { string primernum, segnumero; int num1, num2, suma; System.Console.Write("Ingresa primer num: "); primernum = System.Console.ReadLine(); System.Console.Write("Ingresa segundo num: "); segnumero = Console.ReadLine(); num1 = Int32.Parse(primernum); num2 = Int32.Parse(segnumero); suma = num1 + num2; System.Console.WriteLine("El resultado de la suma es" + suma); Console.Read(); } } }

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

namespace led_univer1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void label1_Click(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { label1.Text = "ledwin "; } } }

MUESTRA SI LA LETRA ES MAYUSCULA O MINUSCULA


using using using using System; System.Collections.Generic; System.Text; System.Runtime.InteropServices;

namespace sentencia_if { class Program { [DllImport("msvcrt")] static extern int _getch(); static void Main(string[] args) { Console.WriteLine("Ingresa un caracter: "); char c = (char)Console.Read(); if (Char.IsLetter(c)) { if (Char.IsLower(c)) { Console.WriteLine("La letra es minuscula"); } else { Console.WriteLine("la letra es mayuscula"); } } else { Console.WriteLine("No es un caracter"); } _getch(); } } }

ELSE E IF (CONSOLA)
using System; using System.Collections.Generic; using System.Text; namespace uno { class Program { static void Main(string[] args) { int valor; Console.Write("Teclee un nmero entero entre 0 y 5: "); valor = Int32.Parse(Console.ReadLine()); if (valor == 0) Console.WriteLine("Puls cero"); else if (valor == 1) Console.WriteLine("Puls uno"); else if (valor == 2) Console.WriteLine("Puls dos"); else if (valor == 3) Console.WriteLine("Puls tre"); else if (valor == 4) Console.WriteLine("Puls cuatro"); else if (valor == 5) Console.WriteLine("Puls cinco"); else Console.WriteLine("Fuera de rango"); Console.ReadLine(); } } }

You might also like