重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
创新互联公司专注于中大型企业的成都做网站、网站设计和网站改版、网站营销服务,追求商业策划与数据分析、创意艺术与技术开发的融合,累计客户上千余家,服务满意度达97%。帮助广大客户顺利对接上互联网浪潮,准确优选出符合自己需要的互联网运用,我们将一直专注成都品牌网站建设和互联网程序开发,在前进的路上,与客户一起成长!
Dim a As Integer = Int(Rnd() * 100)
If a Mod 2 = 0 Then
MsgBox(a "是偶数")
Else
MsgBox(a "是奇数")
End If
End Sub
private function maxnum(byval a() as integer) as integer
dim i as integer
maxnum=a(0)
for i = 1 to ubound(a)
if a(i)maxnum then maxnum=a(i)
next
end function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Randomize() '产生随机数种子 以防止每次生成结果都一样
Dim a(100) As Integer '声明数组存放数据 用来保存随机数结果
Dim max As Integer, min As Integer '声明两个变量存最大值和最小值
min = 1000 : max = 0 '设置初值
For i = 0 To 99 '循环100次
a(i) = Int(Rnd() * 1000 + 1) '用rnd生成一个随机数 由于rnd范围为0-1之间的小数.所以*1000设置他的范围为0到999之间 加1变成1到1000之间
If a(i) = max Then max = a(i) '如果当前数值大于最大值的变量就保存
If a(i) = min Then min = a(i) '如果当前数值小于最小值的变量就保存
Next
MsgBox("最大值为" max)
MsgBox("最小值为" min)
End Sub
'产生10个正整数
Dim intArr(10) As Integer
For i As Integer = 1 To 10
intArr(i - 1) = Int(Rnd() * 99) + 1
Next
'取最小值
Dim intMin As Integer = intArr(0)
For j As Integer = 1 To UBound(intArr) - 1
If intMin intArr(j) Then intMin = intArr(j)
Next
'取最大值
Dim intMax As Integer = intArr(0)
For j As Integer = 1 To UBound(intArr) - 1
If intMax intArr(j) Then intMax = intArr(j)
Next
Dim strTemp As String = ""
For tempi As Integer = 0 To UBound(intArr) - 1
strTemp = strTemp intArr(tempi) ","
Next
MessageBox.Show(strTemp ControlChars.CrLf "min: " intMin.ToString ControlChars.CrLf "max: " intMax.ToString)
double是双精度 有效数值位52位 表示成指数的形式 即指数11位 即表示成
所以180.89305用2进制表示是10110100.1110010010011110111011001011111110110001010110110101
即
180.89305在double中存在的实际数值是
1.01101001110010010011110111011001011111110110001010110110101 *2^7
取小数点后 52位有效值后 等于10进制的180.893049999999998
所及加最后变成了 1808930.99999999998
第一次当然输出近似值1808931
第二次int函数去掉了小数点后的数int就是只取整数的部位的不是四舍五入 所以少了1
Sub Main()
Dim i, j As Integer
Dim tmpStr As String
Console.WriteLine("please input a integer")
tmpStr = Console.ReadLine()
If IsNumeric(tmpStr) And InStr(tmpStr, ".") 1 Then
判断输入是否是整数,IsNumeric(tmpStr) 是判断是否是数字,InStr(tmpStr, ".")是判断是否有小数点.
i = CType(tmpStr, Integer)
Else
MsgBox("not a valid integer!")
Exit Sub
End If
Console.WriteLine("please input another integer")
tmpStr = Console.ReadLine()
If IsNumeric(tmpStr) And InStr(tmpStr, ".") 1 Then
j = CType(tmpStr, Integer)
Else
MsgBox("not a valid integer!")
Exit Sub
End If
Console.WriteLine("the avg is : " ((i + j) / 2).ToString "press enter to exit...")
Console.ReadLine()
End Sub