Click here to Skip to main content
12,632,032 members (27,347 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: VB VB.NET
What is the simpliest way to write code for integer division with a remainder?
Posted 5-Jul-10 7:07am
Comments
radix3 8-Jul-10 11:34am
   
what have you tried till now please post that too
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Checkout the "\" and the "mod" operators.
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

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
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.161208.1 | Last Updated 8 Jul 2010
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100