vb中的整数除法 [英] integer division in vb
本文介绍了vb中的整数除法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
最简单的写整数除法代码的方法是什么?
What is the simpliest way to write code for integer division with a remainder?
推荐答案
检出"\"和"mod" 运算符.
Checkout the "\" and the "mod" operators.
简单代码做区分:
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
这篇关于vb中的整数除法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文