Click here to Skip to main content
Rate this: bad
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
radix3 at 8-Jul-10 11:34am
what have you tried till now please post that too
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Checkout the "\" and the "mod" operators.
Rate this: bad
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)
    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

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

  Print Answers RSS
0 OriginalGriff 339
1 Sergey Alexandrovich Kryukov 119
2 DineshMaind 113
3 majid torfi 75
4 ChauhanAjay 73
0 Sergey Alexandrovich Kryukov 9,192
1 OriginalGriff 8,405
2 CPallini 2,613
3 Richard MacCutchan 2,231
4 Abhinav S 1,938

Advertise | Privacy | Mobile
Web04 | 2.8.140827.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