P. 1
ejercicios de c#

ejercicios de c#

4.5

|Views: 3.708|Likes:
Publicado pormundo23

More info:

Published by: mundo23 on Aug 06, 2009
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as DOCX, PDF, TXT or read online from Scribd
See more
See less

05/23/2013

pdf

text

original

PROGARAMA PARA DE SORTEO using System; using System.Collections.Generic; using System.

Text; namespace Exercici22_UD2 { class Program { static void Main(string[] args) { Random r = new Random(); int num, cupo,r1,r2,r3,r4,n1,n2,n3,n4,a1,a2,a3,a4,c1,c2,c3 ,c4; cupo = r.Next(100000); Console.WriteLine("Que numero tenemos (5 digitos)"); num = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("el numero premiado es " + cupo); n1 = cupo / 10; r1 = cupo % 10; n2 = n1 / 10; r2 = n1 % 10; n3 = n2 / 10; r3 = n2 % 10; n4 = n2 / 10; r4 = n3 / 10; a1 c1 a2 c2 a3 c3 = = = = = = num / 10; num % 10; a1 / 10; a1 % 10; a2 / 10; a2 / 10;

a4 = a3 / 10; c4 = a3 % 10; if (num==cupo) Console.WriteLine("Coincidencia de los 5 digitos, has ganado 33.000 euros"); else if (r1==c1 && r2==c2 && r3==c3 && r4==c4) Console.WriteLine("Coincidencia de los 4 ultimos digitos, has ganado 150 euros"); else if (r1==c1 && r2==c2 && r3==c3) Console.WriteLine("Coincidencia de los 3 ultimos digitos, has guanyat 15 euros"); else if (r1==c1 && r2==c2) Console.WriteLine("Coincidencia de los 2 ultimos digitos, has ganado 5 euros"); else if (r1==c1) Console.WriteLine("Coincidencia en el ultimo digito, has ganado 1,5 euros"); else Console.WriteLine("Ninguna coincidencia, no has ganado nada"); } } }

RELOJ DIGITAL CON ALARMA

using System; using System.Collections.Generic; using System.Text; namespace rellotgeDigitalAmbAlarma

{ class Program { static void Main(string[] args) { Console.ForegroundColor = ConsoleColor.Red; Console.BackgroundColor = ConsoleColor.Yellow; Console.Clear(); int h, m, s, x; int alarmaH, alarmaM, alarmaS; String alarma; Console.WriteLine("Introdueix les hores"); h = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Introdueix els minuts"); m = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Introdueix els segons"); s = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Vols possar alarma, si o no"); alarma = Convert.ToString(Console.ReadLine()); if (alarma == "si") { Console.Clear(); Console.WriteLine("Introdueix les hores de l'alarma"); alarmaH = Convert.ToInt32(Console.ReadLine());

Console.WriteLine("Introdueix els minuts de l'alarma"); alarmaM = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("Introdueix els segons de l'alarma"); alarmaS = Convert.ToInt32(Console.ReadLine()); } else { alarmaH = -1; alarmaM = -1; alarmaS = -1; } while (true) { Console.Clear(); Console.WriteLine("Son les {0}:{1}:{2}", h, m, s); x = Environment.TickCount; while (Environment.TickCount <= x + 1000) ; s = s + 1; if (alarmaH == h && alarmaM == m && alarmaS == s) { Console.Beep(); Console.Beep(); Console.Beep(); } if (s == 60)

{ s = 0; m = m + 1; if (m == 60) { m = 0; h = h + 1; if (h == 24) { h = 0; } } }

} } } }

conversiones de grados

Dejo una imagen Aclaro que se puede acer un poko mas corto con clases Código: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace Centigrados

{ public partial class Form1 : Form { int b,a; double t; int cad; string tot; public Form1() { InitializeComponent(); } private void radioButton1_CheckedChanged(object sender, EventArgs e) { try { a = Convert.ToInt32(textBox1.Text); b = Convert.ToInt32(textBox2.Text); cad = listBox1.Items.Add("Celsius kelvin"); if (a < b) { } else { MessageBox.Show("Error en los datos","Tecnologico de la Paz"); } while (a <= b) { for (int x = a; x <= a; x++) { t = a + 273.15;

tot = x.ToString() + " " + t.ToString(); } listBox1.Items.Add(tot); a++; } } catch (FormatException ms) { MessageBox.Show("Error en los datos de entrada", "Tecnologico de la Paz"); textBox1.Text = ""; textBox2.Text = ""; radioButton1.Checked = false; } } private void button2_Click(object sender, EventArgs e) { radioButton1.Checked = false; radioButton2.Checked = false; radioButton3.Checked = false; radioButton4.Checked = false; radioButton5.Checked = false; radioButton6.Checked = false; listBox1.Items.Clear(); textBox1.Text = ""; textBox2.Text = ""; textBox1.Focus(); } private void Form1_Load(object sender, EventArgs e) { MessageBox.Show("Bienvenidos al convertidor de temperaturas", "Tecnologico de la Paz"); } private void Form1_Load_1(object sender,

EventArgs e) { } private void button1_Click(object sender, EventArgs e) { this.Close(); } private void radioButton2_CheckedChanged(object sender, EventArgs e) { listBox1.Items.Clear(); try { /*if (a < b) { } else { MessageBox.Show("Error en los datos", "Tecnologico de la Paz"); textBox1.Focus(); listBox1.Items.Clear(); }*/ a = Convert.ToInt32(textBox1.Text); b = Convert.ToInt32(textBox2.Text); cad = listBox1.Items.Add("Kelvin Celsius"); while (a <= b) { for (int x = a; x <= a; x++) { t = a - 273.15; tot = x.ToString() + " " + t.ToString();

} listBox1.Items.Add(tot); a++; } } catch (FormatException ms) { MessageBox.Show("Error en los datos de entrada", "Tecnologico de la Paz"); textBox1.Text = ""; textBox2.Text = ""; radioButton2.Checked = false; } } private void radioButton3_CheckedChanged(object sender, EventArgs e) { listBox1.Items.Clear(); try { /*if (a < b) { } else { MessageBox.Show("Error en los datos", "Tecnologico de la Paz"); textBox1.Focus(); textBox1.Text = ""; textBox2.Text = ""; listBox1.Items.Clear(); }*/ a = Convert.ToInt32(textBox1.Text); b = Convert.ToInt32(textBox2.Text); cad =

listBox1.Items.Add("Fahrenhet Celsius"); while (a <= b) { for (int x = a; x <= a; x++) { t = (a - 32)/1.8; tot = x.ToString() + " " + t.ToString(); } listBox1.Items.Add(tot); a++; } } catch (FormatException ms) { MessageBox.Show("Error en los datos de entrada", "Tecnologico de la Paz"); textBox1.Text = ""; textBox2.Text = ""; radioButton3.Checked = false; } } private void radioButton4_CheckedChanged(object sender, EventArgs e) { listBox1.Items.Clear(); try { /*if (a < b) { } else { MessageBox.Show("Error en los datos", "Tecnologico de la Paz"); textBox1.Focus(); textBox1.Text = "";

textBox2.Text = ""; listBox1.Items.Clear(); }*/ a = Convert.ToInt32(textBox1.Text); b = Convert.ToInt32(textBox2.Text); cad = listBox1.Items.Add("Celsius Fahrenhet"); while (a <= b) { for (int x = a; x <= a; x++) { t = (a *1.8) +32; tot = x.ToString() + " " + t.ToString(); } listBox1.Items.Add(tot); a++; } } catch (FormatException ms) { MessageBox.Show("Error en los datos de entrada", "Tecnologico de la Paz"); textBox1.Text = ""; textBox2.Text = ""; radioButton4.Checked = false; } } private void radioButton5_CheckedChanged(object sender, EventArgs e) { listBox1.Items.Clear(); try { /*if (a < b)

{ } else { MessageBox.Show("Error en los datos", "Tecnologico de la Paz"); textBox1.Focus(); textBox1.Text = ""; textBox2.Text = ""; listBox1.Items.Clear(); }*/ a = Convert.ToInt32(textBox1.Text); b = Convert.ToInt32(textBox2.Text); cad = listBox1.Items.Add("Kelvin Fahrenhet"); while (a <= b) { for (int x = a; x <= a; x++) { t = (a * 1.8) -459.67 ; tot = x.ToString() + " " + t.ToString(); } listBox1.Items.Add(tot); a++; } } catch (FormatException ms) { MessageBox.Show("Error en los datos de entrada", "Tecnologico de la Paz"); textBox1.Text = ""; textBox2.Text = ""; radioButton5.Checked = false; } }

private void radioButton6_CheckedChanged(object sender, EventArgs e) { listBox1.Items.Clear(); try { /*if (a < b) { } else { MessageBox.Show("Error en los datos", "Tecnologico de la Paz"); textBox1.Focus(); textBox1.Text = ""; textBox2.Text = ""; listBox1.Items.Clear(); }*/ a = Convert.ToInt32(textBox1.Text); b = Convert.ToInt32(textBox2.Text); cad = listBox1.Items.Add("Fahrenhet Kelvin"); while (a <= b) { for (int x = a; x <= a; x++) { t = (a + 459.67) / 1.8; tot = x.ToString() + " " + t.ToString(); } listBox1.Items.Add(tot); a++; } } catch (FormatException ms)

{ MessageBox.Show("Error en los datos de entrada", "Tecnologico de la Paz"); textBox1.Text = ""; textBox2.Text = ""; radioButton6.Checked = false; } } private void textBox2_Enter(object sender, EventArgs e) { } } }

You're Reading a Free Preview

Descarga
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->