• Register now to get access to thousands of Tutorials, Leaked content, Hot NSFW and much more. Join us as we build and grow the community.

Advertise Here

Advertise Here

Advertise Here

Compute Square Root using Math.Sqrt in C#

Fam1337

Influence Marketer
F Rep
0
0
0
Rep
0
F Vouches
0
0
0
Vouches
0
Posts
86
Likes
97
Bits
2 MONTHS
2 2 MONTHS OF SERVICE
LEVEL 2 1000 XP
In this tutorial, i will introduce another function in C# regarding the Math Functions, the Math.Sqrt(). Math.Sqrt() function provides to compute the square root of a number.

So, now let's start this tutorial!

1. Let's start with creating a Windows Form Application for this tutorial by following the following steps in Microsoft Visual Studio 2010: Go to File, click New Project, and choose Windows Application.


2. Next, add two TextBoxes named TextBox1 and TextBox2 then leave it as blank. TextBox1 will be your whole number as an input, and TextBox2 will be the result of the square root you've input. Now, add a Button named Button1 to see the result of the Square Root and displayed in TextBox2. You must design your interface like this:

squarerootdesign_0.png


3. Now, put this code in Button1_Click. This will display the result of the square root in TextBox2.

  1. private

    void

    button1_Click(

    object

    sender, EventArgs e)
  2. {
  3. int

    num1;
  4. num1=

    System

    .

    Convert

    .

    ToInt32

    (

    (

    textBox1.

    Text

    )

    )

    ;
  5. textBox2.

    Text

    =

    System

    .

    Convert

    .

    ToString

    (

    Math.

    Sqrt

    (

    num1)

    )

    ;
  6. }

We initialized num1 as Integer to hold the value inputted in TextBox1. Then in TextBox2, we compute the square root of a number inputted in num1 with the syntax Math.Sqrt(num1). Math.

Sqrt

(

)

Function

is only for calculating the square root of number.

Output:

squarerootoutput_1.png


For more inquiries and need programmer for your thesis systems in any kind of programming languages, just contact my number below.

Best Regards,

Engr. Lyndon Bermoy
IT Instructor/System Developer/Android Developer/Freelance Programmer

If you have some queries, feel free to contact the number or e-mail below.
Mobile: 09488225971
Landline: 826-9296
E-mail:[email protected]

Add and Follow me on Facebook: https://www.facebook.com/donzzsky

Visit and like my page on Facebook at: https://www.facebook.com/BermzISware

 

Create an account or login to comment

You must be a member in order to leave a comment

Create account

Create an account on our community. It's easy!

Log in

Already have an account? Log in here.

452,500

350,639

350,649

Top