Tuesday, 30 October 2012

C# code to find Sum And Average of 3 Numbers

C# Code to find Sum And Average of 3 Numbers


It is easy to find Sum and Average of 3 numbers in C# .Firstly create a new project in visual studio with C# Code .Open the form and drag and drop 5 text boxes , 3 for inputting 3 numbers and 2 for display sum and average.Also we need 5 labels for labeling 5 text boxes.
insert these 5 text boxes ,5 labels and a button. after inserting these controls select the first textbox and set the name as txtFirstNumber,select the second textbox and set the name as txtSecondNumber ,select the third textbox and set the name as txtThirdNumber,select the 4th  textbox and set the name as txtSum,select the 5th textbox and set the name as txtAverage and select the button and set the name as btnSumAndAverage.set the labels Text as appropriate name.after completing design the form is like this

The final design with a sample result values.


double click on the button and write the code below:



        private void btnSumAndAverage_Click(object sender, EventArgs e)
        {
            txtSum.Text = (Convert.ToInt32(txtFirstNumber.Text) + Convert.ToInt32(txtSecondNumber.Text)     
           + Convert.ToInt32(txtThirdNumber.Text)).ToString();
            txtAverage.Text = (Convert.ToInt32(txtSum.Text) / 3).ToString();
        }

See also:
 

        Code for Find FACTORIAL of a Given Number From TextBox

      Code For Check The Given Number is +VE or -Ve

  

          

No comments:

Post a Comment