VB.Net/Development/Math Function
Содержание
- 1 Acos and Cos
- 2 Asin and Sin
- 3 Atan and Tan
- 4 Calculating compound interest
- 5 Math class: Square root, absolute value, Pi and Power
- 6 Math.Max Demo
- 7 Math: Min, Max, Exp, Ceil, Round and Log10
- 8 Math: square root
- 9 Power in VB
- 10 Power ^ in VB.net
- 11 Rnd Demo
- 12 Round in Math
- 13 Sign in Math
- 14 Square Root in Math package
- 15 To the Power
Acos and Cos
<source lang="vbnet"> Imports System Imports System.Data Imports System.Diagnostics public class MainClass
Shared Sub Main() Console.WriteLine(System.Math.Acos(0)) Console.WriteLine(System.Math.Cos(10)) End Sub
End Class
</source>
Asin and Sin
<source lang="vbnet"> Imports System Imports System.Data Imports System.Diagnostics public class MainClass
Shared Sub Main() Console.WriteLine(System.Math.Asin(0)) Console.WriteLine(System.Math.Sin(10)) End Sub
End Class
</source>
Atan and Tan
<source lang="vbnet"> Imports System public class MainClass
Shared Sub Main() Console.WriteLine(System.Math.Atan(10)) Console.WriteLine(System.Math.Tan(10)) End Sub
End Class
</source>
Calculating compound interest
<source lang="vbnet"> Imports System Public Class MainClass
Shared Sub Main(ByVal args As String()) Dim amount, principal As Decimal " dollar amounts Dim rate As Double " interest rate Dim year As Integer " year counter Dim output As String " amount after each year principal = 1000 rate = 0.05 output = "Year" & vbTab & "Amount on deposit" & vbCrLf " calculate amount after each year For year = 1 To 10 amount = principal * (1 + rate) ^ year output &= year & vbTab & _ String.Format("{0:C}", amount) & vbCrLf Next " display output Console.WriteLine("Compound Interest" & output) End Sub
End Class
</source>
Math class: Square root, absolute value, Pi and Power
<source lang="vbnet"> Imports System.IO Module Module1
Sub Main() Console.WriteLine("Absolute value of -1 is " & Math.Abs(-1)) Console.WriteLine("Square Root of 144 is " & Math.Sqrt(144)) Console.WriteLine("Value for PI is " & Math.PI) Console.WriteLine("10 raised to the power of 2 is " & Math.Pow(10, 2)) End Sub
End Module
</source>
Math.Max Demo
<source lang="vbnet"> Imports System Public Class MainClass
Shared Sub Main(ByVal args As String()) Console.WriteLine(Math.Max(Math.Max(1, 2), 3)) End Sub
End Class
</source>
Math: Min, Max, Exp, Ceil, Round and Log10
<source lang="vbnet"> Module Module1
Sub Main() Console.WriteLine("Ceiling(1.1), Ceiling(0.9) = " & Math.Ceiling(1.1) & " " & Math.Ceiling(0.9)) Console.WriteLine("Exp(5) = " & Math.Exp(5)) Console.WriteLine("Log10(100) = " & Math.Log10(100)) Console.WriteLine("Max(1001, 100) = " & Math.Max(1001, 100)) Console.WriteLine("Min(1001, 100) = " & Math.Min(1001, 100)) Console.WriteLine("Floor(1.1), Floor(0.9) = " & Math.Floor(1.1) & " " & Math.Floor(0.9)) Console.WriteLine("Round(1.1), Round(0.9) = " & Math.Round(1.1) & " " & Math.Round(0.9)) End Sub
End Module
</source>
Math: square root
<source lang="vbnet"> Imports System Public Class MainClass
Shared Sub Main(ByVal args As String()) " Calculate square root of 2 Dim root As Double = Math.Sqrt(2) Console.WriteLine("The square root of 2 is " & root, _ "The Square Root of 2") End Sub
End Class
</source>
Power in VB
<source lang="vbnet"> Imports System public class MainClass
Shared Sub Main()
Dim value As Integer = 5 Dim power As Integer = 4 Console.WriteLine("{0} to the {1}th power is {2}", _ value, power, value ^ power) End Sub
End Class
</source>
Power ^ in VB.net
<source lang="vbnet"> Imports System Public Class MainClass
Shared Sub Main(ByVal args As String()) Dim i As Integer " counter Console.WriteLine("Number" & vbTab & "Square" & vbCrLf) " square numbers from 1 to 10 For i = 1 To 10 Console.WriteLine(i & vbTab & Square(i)) Next End Sub Shared Function Square(ByVal y As Integer) As Integer Return y ^ 2 End Function
End Class
</source>
Rnd Demo
<source lang="vbnet"> Imports System Imports System.Data Imports System.Diagnostics public class MainClass
Shared Sub Main() Console.WriteLine(Rnd()) End Sub
End Class
</source>
Round in Math
<source lang="vbnet"> Imports System Imports System.Data Imports System.Diagnostics public class MainClass
Shared Sub Main() Console.WriteLine(System.Math.Round(1.4)) End Sub
End Class
</source>
Sign in Math
<source lang="vbnet"> Imports System public class MainClass
Shared Sub Main() Console.WriteLine(System.Math.Sign(-1)) Console.WriteLine(System.Math.Sign(0)) Console.WriteLine(System.Math.Sign(1)) End Sub
End Class
</source>
Square Root in Math package
<source lang="vbnet"> Imports System Imports System.Data Imports System.Diagnostics public class MainClass
Shared Sub Main() Console.WriteLine(System.Math.Sqrt(4)) End Sub
End Class
</source>
To the Power
<source lang="vbnet"> Imports System Public Class MainClass
Shared Sub Main(ByVal args As String()) Dim value As Integer = 5 Dim power As Integer = 4 Console.WriteLine("{0} to the {1}th power is {2}", _ value, power, value ^ power) End Sub
End Class
</source>