Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
What is the simpliest way to write code for integer division with a remainder?
Posted
Comments
radix3 8-Jul-10 11:34am    
what have you tried till now please post that too

Checkout the "\" and the "mod" operators.
 
Share this answer
 
simple code to do divison:
Sub Main()
    Dim var1 As Integer = 17
    Dim var2 As Integer = 4
    Dim resDiv As Integer = var1 / var2 ' resDiv=4
    Dim resMod As Integer = var1 Mod var2 ' resMod=1
End Sub



and the following full complete example to do division:
Module Division
    Sub Main()
        Dim var1 As Integer
        Dim var2 As Integer
        Console.WriteLine("Enter the first number:")
        var1 = CInt(Console.ReadLine)
        Console.WriteLine("Enter the second number:")
        var2 = CInt(Console.ReadLine)
        DivMod(var1, var2)
        Console.Read()
    End Sub
    Sub DivMod(ByVal v1 As Integer, ByVal v2 As Integer)
        Dim divRes As Integer = v1 / v2
        Dim modRes As Integer = v1 Mod v2
        Console.WriteLine(String.Format("Division Result:{0} and Remainder Result:{1}", divRes.ToString, modRes.ToString))
    End Sub
End Module
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900