Translate

Friday, 31 May 2013

Arithmetic Operators Example in VB.NET


Programming Examples using Arithmetic Operations

In this Blog we will some programs using arithmetics operations. So far we saw assigning values to variable and calculate and display result. Assigning values to variables called 'Constants' i.e., the values do not change during execution of a program. Now we are going to see how to set or assign values to vairables during execution.

Module Example3
    Sub Main()
        Dim Num1, Num2 As Integer
        Dim AddResult, SubResult, DivResult, MulResult As Integer
        Console.WriteLine("Enter Value for Num1: ")
        Num1 = Console.ReadLine()
        Console.WriteLine("Enter Value for Num2: ")
        Num2 = Console.ReadLine()

        AddResult = Num1 + Num2
        SubResult = Num1 - Num2
        DivResult = Num1 / Num2
        MulResult = Num1 * Num2

        Console.WriteLine("Results of Arithmetic Operations.....")

        Console.WriteLine("Addition Result: " & AddResult)
        Console.WriteLine("Subtraction Result: " & SubResult)
        Console.WriteLine("Divison Result: " & DivResult)
        Console.WriteLine("Multiplication Result: " & MulResult)

        Console.WriteLine(".............End......................")
        Console.ReadKey()

    End Sub
End Module

 The above programiming  examples shows how to get input duing runtime and shows the output you have seen that In the Console.WriteLine I have used '&' (Ampersand)  this actually concatenate two string or two words. i.e., it concatenate AddResult  with 'Addition Result:' type and run the program you will notice it.


We will see more examples in the next blog.

No comments:

Post a Comment