13,293,474 members (54,861 online)
Rate this:
See more:
What is the simpliest way to write code for integer division with a remainder?
Posted 5-Jul-10 7:07am

what have you tried till now please post that too

Rate this:

## Solution 1

Checkout the "\" and the "mod" operators.
Rate this:

## 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:")
Console.WriteLine("Enter the second number:")
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```
v2

Top Experts
Last 24hrsThis month
 Jochen Arndt 340 OriginalGriff 288 Dave Kreskowiak 230 ppolymorphe 100 Richard MacCutchan 85
 OriginalGriff 2,076 Jochen Arndt 1,130 Richard MacCutchan 1,040 CPallini 875 ppolymorphe 874