Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: VB.NET
What is the simpliest way to write code for integer division with a remainder?
Posted 5-Jul-10 6:07am
Comments
radix3 at 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
0 OriginalGriff 205
1 Sergey Alexandrovich Kryukov 165
2 jlopez788 109
3 Rob Philpott 100
4 Prakriti Goyal 97
0 OriginalGriff 6,837
1 Sergey Alexandrovich Kryukov 5,589
2 Maciej Los 3,479
3 Peter Leow 3,323
4 DamithSL 2,505


Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 8 Jul 2010
Copyright © CodeProject, 1999-2014
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