Está en la página 1de 5

Calculadora aritmtica

Suma

Resta

Multiplicacin

Divisin

Raz

Potencia

Cdigo de programa
using using using using using using using System; System.Collections.Generic; System.ComponentModel; System.Data; System.Drawing; System.Text; System.Windows.Forms;

namespace WindowsApplication1 { public partial class Form1 : Form { double x,y; public Form1() { InitializeComponent(); } private void btn_mas_Click(object sender, EventArgs e) { if (this.textBox1.Text != "" && this.textBox2.Text != "") { x = Convert.ToDouble(this.textBox1.Text); y = Convert.ToDouble(this.textBox2.Text); this.textBox3.Text = string.Format("{0:f2}", x + y); } } private void btn_menos_Click(object sender, EventArgs e) { if (this.textBox1.Text != "" && this.textBox2.Text != "") { x = Convert.ToDouble(this.textBox1.Text); y = Convert.ToDouble(this.textBox2.Text); this.textBox3.Text = string.Format("{0:f2}", x - y); } } private void btn_por_Click(object sender, EventArgs e) { if (this.textBox1.Text != "" && this.textBox2.Text != "") { x = Convert.ToDouble(this.textBox1.Text); y = Convert.ToDouble(this.textBox2.Text); this.textBox3.Text = string.Format("{0:f2}", x * y); } } private void btn_entre_Click(object sender, EventArgs e) { if (this.textBox1.Text != "" && this.textBox2.Text != "") {

x = Convert.ToDouble(this.textBox1.Text); y = Convert.ToDouble(this.textBox2.Text); if (y == 0) { this.textBox3.Text = "error by Zero"; } else { this.textBox3.Text = string.Format("{0:f2}", x / y); } } } private void btn_raiz_Click(object sender, EventArgs e) { if (this.textBox1.Text != "") { x = Convert.ToDouble(this.textBox1.Text); double resultado = Math.Sqrt(x); this.textBox3.Text = string.Format("{0:f2}", resultado); } } private void btn_potencia_Click(object sender, EventArgs e) { if (this.textBox1.Text != "" && this.textBox2.Text != "") { x = Convert.ToDouble(this.textBox1.Text); y = Convert.ToDouble(this.textBox2.Text); double resultado = Math.Pow(x, y); this.textBox3.Text = string.Format("{0:f2}", resultado); } } private void button1_Click(object sender, EventArgs e) { this.textBox1.Text = ""; this.textBox2.Text = ""; this.textBox3.Text = ""; } } }

También podría gustarte