C#.NET Program 1


Output:


Code:

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 Program_1
{
    public partial class Form1 : Form
    {

        double num1;
        double num2;
        string operation;

        public Form1()
        {
            InitializeComponent();
            textBox1.ReadOnly = true;
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void input(string a)
        {
            if (textBox1.Text == "0")
                textBox1.Text = a;
            else
                textBox1.Text += a;
        }

// For 1
        private void button1_Click(object sender, EventArgs e)
        {
            input("1");
        }

// For 2
        private void button2_Click(object sender, EventArgs e)
        {
            input("2");
        }

// For 3
        private void button3_Click(object sender, EventArgs e)
        {
            input("3");
        }
// For 4
        private void button4_Click(object sender, EventArgs e)
        {
            input("4");
        }

// For 5
        private void button5_Click(object sender, EventArgs e)
        {
            input("5");
        }
// For 6
        private void button6_Click(object sender, EventArgs e)
        {
            input("6");
        }

// For 7
        private void button7_Click(object sender, EventArgs e)
        {
            input("7");
        }

// For 8
        private void button8_Click(object sender, EventArgs e)
        {
            input("8");
        }

// For 9
        private void button9_Click(object sender, EventArgs e)
        {
            input("9");
        }

// For 0
        private void button10_Click(object sender, EventArgs e)
        {
            input("0");
        }

// For Addition
        private void button18_Click(object sender, EventArgs e)
        {
            num1 = double.Parse(textBox1.Text);
            operation = "+" ;
            textBox1.Text = "0";
        }

       // For Subtraction
        private void button20_Click(object sender, EventArgs e)
        {
            num1 = double.Parse(textBox1.Text);
            operation = "-" ;
            textBox1.Text = "0";
        }

// For Multiplication
        private void button21_Click(object sender, EventArgs e)
        {
            num1 = double.Parse(textBox1.Text);
            operation = "*" ;
            textBox1.Text = "0";
        }

// For Divison
        private void button22_Click(object sender, EventArgs e)
        {
            num1 = double.Parse(textBox1.Text);
            operation = "/" ;
            textBox1.Text = "0";
        }

// For Power
        private void button12_Click(object sender, EventArgs e)
        { 
           num1 = double.Parse(textBox1.Text);
           operation = "^" ;
           textBox1.Text = "0";
        }

// For Equal Button And Operation
        private void button19_Click(object sender, EventArgs e)
        {
            num2 = double.Parse(textBox1.Text);

            switch (operation)
            {
                          //Addition Function
                case "+": textBox1.Text = (num1 + num2).ToString();
                          break;

                          //Subtraction Function
                case "-": textBox1.Text = (num1 - num2).ToString();
                          break;

                          //Multiplication Function
                case "*": textBox1.Text = (num1 * num2).ToString();
                          break;
                          
                          //Divison Function
                case "/": textBox1.Text = (num1 / num2).ToString();
                          break;  
                          
                          //Power Function
                case "^": textBox1.Text = System.Math.Pow(num1, num2).ToString();
                          break; 
            }
        }

// Clear
        private void button17_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
        }


        //Logeritham Function
        private void button14_Click(object sender, EventArgs e)
        {
            textBox1.Text = (Math.Log(double.Parse(textBox1.Text))).ToString();
        }


        //Factorial Function
        private void button15_Click(object sender, EventArgs e)
        {
            long f = 1;
            for (long i = 1; i <= long.Parse(textBox1.Text); i++)
            {
                 f = f * i;
            }
            textBox1.Text = f.ToString();
        }


        //Sq.Root Function
        private void button16_Click(object sender, EventArgs e)
        {
            textBox1.Text = (Math.Sqrt(double.Parse(textBox1.Text))).ToString();
        }

        //Square Function
        private void button13_Click(object sender, EventArgs e)
        {
            textBox1.Text = Convert.ToString(Convert.ToDouble(textBox1.Text) * Convert.ToDouble(textBox1.Text)); 
        }
    }
}

No comments:

Post a Comment