Search - Articles
DevASP.NET for ASP.NET, VB.NET, XML and C# (C-Sharp) Developers Tuesday, March 03, 2009
Dev Articles
Search Directory
ASP.NET
VB.Net
C-Sharp
SQL Server
 

Multiplication power logarithm Math operations using Math class VB and C#.net 2.0

Author: Maliha Atteeq
Download Source Code : 971_Math.zip

In this simple article you will learn that how we can get log and e raised to power and how to do big multiplication using "Math class" in VB and C# (.net 2.0).

 Logarithm With base 10:

To get the logarithm of a number with base 10. For this purpose we have a static function of Math class named Log10 (). This function takes and returns a double value.

To demonstrate make a window application. Drag one text box and one button on form.

Now write the following code on Button click event:

C#

private void btn_log10_Click(object sender, EventArgs e)

        {

            string str = txt_log10.Text;

            double value = Convert.ToDouble(str);

            double log;

            log = System.Math.Log10(value);

            MessageBox.Show(log.ToString());

        }

VB

Private Sub btn_log10_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim str As String = txt_log10.Text

        Dim value As Double = Convert.ToDouble(str)

        Dim log As Double

        log = System.Math.Log10(value)

        MessageBox.Show(log.ToString())

    End Sub

This is simple code to get the logarithm with base 10.

Logarithm With Given base:

If you want to get the logarithm of a number according to specific base. For this purpose we have a static function of Math class named Log (). This function takes two parameters one is base and other is number to whom you want to take the log.

To demonstrate make a window application. Drag two text boxes and one button on form.

Now write the following code on Button click event:

C#

private void btn_logbase_Click(object sender, EventArgs e)

        {

            string str = txt_logval.Text;

            string str2 = txt_base.Text;

            double value = Convert.ToDouble(str);

            double bs = Convert.ToDouble(str2);

            double log;

            log = System.Math.Log(value, bs);

            MessageBox.Show(log.ToString());

        }

VB

Private Sub btn_logbase_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim str As String = txt_logval.Text

        Dim str2 As String = txt_base.Text

        Dim value As Double = Convert.ToDouble(str)

        Dim bs As Double = Convert.ToDouble(str2)

        Dim log As Double

        log = System.Math.Log(value, bs)

        MessageBox.Show(log.ToString())

    End Sub

This is simple code to get the logarithm with given base.

Exp:

To get the e raised to power of given number we have a static function of math class named Exp (). This function takes and returns double value.

To demonstrate make a window application. Drag one text box and one button on form.

Now write the following code on Button click event:

C#

private void btn_Exp_Click(object sender, EventArgs e)

        {

            string str = txt_Exp.Text;

            double val = Convert.ToDouble(str);

            double ans;

            ans = System.Math.Exp(val);

            string str2 = ans.ToString();

            MessageBox.Show("Ans" + str2);

        }

VB

Private Sub btn_Exp_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim str As String = txt_Exp.Text

        Dim val As Double = Convert.ToDouble(str)

        Dim ans As Double

        ans = System.Math.Exp(val)

        Dim str2 As String = ans.ToString()

        MessageBox.Show("Ans" & str2)

    End Sub

Big Multiplication:

If you want to get the full product of two 32 bit integers for this purpose we have a function of Math class named BigMul (). This function takes two integers as parameter and returns a long value.

To demonstrate make a window application. Drag two text boxes and one button on form.

Now write the following code on Button click event:

C#

private void btn_mul_Click(object sender, EventArgs e)

        {

            string str = txt_first.Text;

            string str2 = txt_second.Text;

            int a = Convert.ToInt32(str);

            int b = Convert.ToInt32(str2);

            long ans = 0;

            ans = System.Math.BigMul(a, b);

            MessageBox.Show(ans.ToString());

        }   

VB

Private Sub btn_mul_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim str As String = txt_first.Text

        Dim str2 As String = txt_second.Text

        Dim a As Integer = Convert.ToInt32(str)

        Dim b As Integer = Convert.ToInt32(str2)

        Dim ans As Long = 0

        ans = System.Math.BigMul(a, b)

        MessageBox.Show(ans.ToString())

    End Sub

This is simple code to get the full product of two 32 bit integers..

Now write the following code on FORM LOAD event:

C#

private void Form1_Load(object sender, EventArgs e)

        {

            this.Text = "DEVASP MATH APPLICATION";          

        }

VB

Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)

        Me.Text = "DEVASP MATH APPLICATION"

End Sub

 

This simple article tells that how we can get log and e raised to power and how to do big multiplication using "Math class" in VB and C# (.net 2.0).

   
Add Article Comment:
Name :
Email Address :
   
Comments :
 
   
<< Truncate square root ceiling floor Math operations using Math class VB and C#.net 2.0

Disclaimer - Privacy
© 2002-2017 DevASP.net