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 Calculator
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
double a, b, c;
string choice;
private void btnMins_Click(object sender, EventArgs e)
{
a = Convert.ToDouble(txtBox.Text);
choice = "-";
}
private void btn1_Click(object sender, EventArgs e)
{
txtBox.Text += "1";
}
private void btn2_Click(object sender, EventArgs e)
{
txtBox.Text += "2";
}
private void btn3_Click(object sender, EventArgs e)
{
txtBox.Text += "3";
}
private void btn4_Click(object sender, EventArgs e)
{
txtBox.Text += "4";
}
private void btn5_Click(object sender, EventArgs e)
{
txtBox.Text += "5";
}
private void btn6_Click(object sender, EventArgs e)
{
txtBox.Text += "6";
}
private void btn7_Click(object sender, EventArgs e)
{
txtBox.Text += "7";
}
private void btn8_Click(object sender, EventArgs e)
{
txtBox.Text += "8";
}
private void btn9_Click(object sender, EventArgs e)
{
txtBox.Text += "9";
}
private void btnZero_Click(object sender, EventArgs e)
{
if (txtBox.Text != "")
txtBox.Text += "0";
}
private void btnDot_Click(object sender, EventArgs e)
{
if (txtBox.Text.IndexOf(".") < 0)
if (txtBox.Text == "")
txtBox.Text += "0.";
else
txtBox.Text += ".";
}
private void btnPlus_Click(object sender, EventArgs e)
{
a = Convert.ToDouble(txtBox.Text);
choice = "+";
txtBox.Clear();
}
private void btnMul_Click(object sender, EventArgs e)
{
a = Convert.ToDouble(txtBox.Text);
choice = "*";
txtBox.Clear();
}
private void btnDi_Click(object sender, EventArgs e)
{
a = Convert.ToDouble(txtBox.Text);
choice = "/";
txtBox.Clear();
}
private void btnCe_Click(object sender, EventArgs e)
{
txtBox.Text = string.Empty;
}
private void btnAc_Click(object sender, EventArgs e)
{
txtBox.Enabled = true;
txtBox.Text = "0";
btnZero.Enabled = true;
btn1.Enabled = true;
btn2.Enabled = true;
btn3.Enabled = true;
btn4.Enabled = true;
btn5.Enabled = true;
btn6.Enabled = true;
btn7.Enabled = true;
btn8.Enabled = true;
btn9.Enabled = true;
btnEqual.Enabled = true;
}
private void btnpn_Click(object sender, EventArgs e)
{
if (txtBox.Text.Contains("-"))
{
txtBox.Text = txtBox.Text.Remove(0, 1);
}
else
{
txtBox.Text = "-" + txtBox.Text;
}
}
private void btnRem_Click(object sender, EventArgs e)
{
a = Convert.ToDouble(txtBox.Text);
choice = "%";
txtBox.Clear();
}
private void btnEqual_Click(object sender, EventArgs e)
{
b = Convert.ToDouble(txtBox.Text);
switch(choice)
{
case "+":
c=a+b;
txtBox.Text=c.ToString();
break;
case "-":
c=a-b;
txtBox.Text=c.ToString();
break;
case"*":
c=a*b;
txtBox.Text=c.ToString();
break;
case "/":
if(b==0)
{
txtBox.Text="0.0";
break;
}
else
{
c=a/b;
txtBox.Text=c.ToString();
break;
}
case "%":
c=a%b;
txtBox.Text=c.ToString();
break;
case"X^y":
c=System.Math.Pow(Convert.ToDouble(a),Convert.ToDouble(b));
txtBox.Text=c.ToString();
break;
case "nPr":
int s,d,f;
s=factorial(Convert.ToInt32(a));
d=factorial(Convert.ToInt32(a)-Convert.ToInt32(txtBox.Text));
txtBox.Text=Convert.ToString(s/d);
break;
case "nCr":
s=factorial(Convert.ToInt32(a));
d=factorial(Convert.ToInt32(a)-Convert.ToInt32(txtBox.Text));
f=factorial(Convert.ToInt32(txtBox.Text));
txtBox.Text=Convert.ToString(s/(d*f));
break;
}
}
private int factorial(int p)
{
int i = 1;
for (int j = 1; j <= i; j++)
{
i = i * j;
}
return i;
}
private void btnOFF_Click(object sender, EventArgs e)
{
txtBox.Enabled = false;
txtBox.Text = "";
btnZero.Enabled = false;
btn1.Enabled = false;
btn2.Enabled = false;
btn3.Enabled = false;
btn4.Enabled = false;
btn5.Enabled = false;
btn6.Enabled = false;
btn7.Enabled = false;
btn8.Enabled = false;
btn9.Enabled = false;
btnEqual.Enabled = false;
}
private void btnX2_Click(object sender, EventArgs e)
{
c = Convert.ToDouble(txtBox.Text) + Convert.ToDouble(txtBox.Text);
txtBox.Text = c.ToString();
}
private void btnx3_Click(object sender, EventArgs e)
{
c = Convert.ToDouble(txtBox.Text) + Convert.ToDouble(txtBox.Text) + Convert.ToDouble(txtBox.Text);
txtBox.Text = c.ToString();
}
private void btnxy_Click(object sender, EventArgs e)
{
a = Convert.ToDouble(txtBox.Text);
choice = "x^y";
txtBox.Clear();
}
private void btnPi_Click(object sender, EventArgs e)
{
txtBox.Text = "3.14159265359";
}
private void btnlnx_Click(object sender, EventArgs e)
{
c = System.Math.Log(Convert.ToDouble(txtBox.Text));
txtBox.Text = c.ToString();
}
private void btnSin_Click(object sender, EventArgs e)
{
if(rbRadian.Checked==true)
{
txtBox.Text=Convert.ToString(System.Math.Sin(Convert.ToDouble(txtBox.Text)));
}
else
{
txtBox.Text=Convert.ToString(System.Math.Sin((Convert.ToDouble(System.Math.PI)/180)*(Convert.ToDouble(txtBox.Text))));
}
}
private void btnBinry_Click(object sender, EventArgs e)
{
int p;
string counter=" ";
p =Convert.ToInt32(txtBox.Text);
while (p >= 1)
{
counter = (p % 2) + counter;
p = p / 2;
}
txtBox.Text = counter;
}
private void btnBack_Click(object sender, EventArgs e)
{
string k = txtBox.Text;
int n = k.Length;
txtBox.Text = (k.Substring(0, n - 1));
}
private void btnxn_Click(object sender, EventArgs e)
{
int tr=1;
for (int i = 1; i <= Convert.ToInt16(txtBox.Text); i++)
{
tr = i * tr;
}
txtBox.Text = tr.ToString();
}
private void btnNpr_Click(object sender, EventArgs e)
{
a = Convert.ToDouble(txtBox.Text);
choice = "nPr";
txtBox.Clear();
}
private void btnNcr_Click(object sender, EventArgs e)
{
a = Convert.ToDouble(txtBox.Text);
choice = "nCr";
txtBox.Clear();
}
private void btnCos_Click(object sender, EventArgs e)
{
if (rbRadian.Checked == true)
{
txtBox.Text = Convert.ToString(System.Math.Cos(Convert.ToDouble(txtBox.Text)));
}
else
{
txtBox.Text=Convert.ToString(System.Math.Cos((Convert.ToDouble(System.Math.PI)/180*(Convert.ToDouble(txtBox.Text)))));
}
}
private void btnTan_Click(object sender, EventArgs e)
{
if (rbRadian.Checked == true)
{
txtBox.Text = Convert.ToString(System.Math.Tan(Convert.ToDouble(txtBox.Text)));
}
else
{
txtBox.Text=Convert.ToString(System.Math.Tan((Convert.ToDouble(System.Math.PI)/180*(Convert.ToDouble(txtBox.Text)))));
}
}
private void btnsin1_Click(object sender, EventArgs e)
{
if (rbRadian.Checked == true)
{
txtBox.Text = Convert.ToString(System.Math.Asin(Convert.ToDouble(txtBox.Text)));
}
else
{
txtBox.Text=Convert.ToString(System.Math.Asin((Convert.ToDouble(System.Math.PI)/180*(Convert.ToDouble(txtBox.Text)))));
}
}
private void btnCos1_Click(object sender, EventArgs e)
{
if (rbRadian.Checked == true)
{
txtBox.Text = Convert.ToString(System.Math.Acos(Convert.ToDouble(txtBox.Text)));
}
else
{
txtBox.Text=Convert.ToString(System.Math.Acos((Convert.ToDouble(System.Math.PI)/180*(Convert.ToDouble(txtBox.Text)))));
}
}
private void btnTan1_Click(object sender, EventArgs e)
{
if (rbRadian.Checked == true)
{
txtBox.Text = Convert.ToString(System.Math.Atan(Convert.ToDouble(txtBox.Text)));
}
else
{
txtBox.Text = Convert.ToString(System.Math.Atan((Convert.ToDouble(System.Math.PI) / 180 * (Convert.ToDouble(txtBox.Text)))));
}
}
private void btnSqrt_Click(object sender, EventArgs e)
{
c = (System.Math.Sqrt(Convert.ToDouble(txtBox.Text)));
txtBox.Text = c.ToString();
}
private void btnlogx_Click(object sender, EventArgs e)
{
c = (System.Math.Log10(Convert.ToDouble(txtBox.Text)));
txtBox.Text = c.ToString();
}
private void btn1x_Click(object sender, EventArgs e)
{
c = Convert.ToDouble(1.0 / Convert.ToDouble(txtBox.Text));
txtBox.Text = c.ToString();
}
private void btnfor_Click(object sender, EventArgs e)
{
int o;
double y;
o = Int32.Parse(txtBox.Text);
y = 5 * (o - 32) / 9;
txtBox.Text = y.ToString();
}
private void btnDoll_Click(object sender, EventArgs e)
{
double f, g;
f = double.Parse(txtBox.Text);
g = (f / 154.92);
txtBox.Text = g.ToString();
}
private void btnperc_Click(object sender, EventArgs e)
{
int f;
int h=100;
f=Int32.Parse(txtBox.Text);
f = f * h;
txtBox.Text=f+"%".ToString();
}
private void btnHexa_Click(object sender, EventArgs e)
{
}
}
}
No comments:
Post a Comment