Private?Sub?Button1_Click(ByVal?sender?As?System.Object,?ByVal?e?As?System.EventArgs)?Handles?Button1.Click
創(chuàng)新互聯(lián)公司專注于中大型企業(yè)的成都做網(wǎng)站、網(wǎng)站設(shè)計(jì)和網(wǎng)站改版、網(wǎng)站營(yíng)銷服務(wù),追求商業(yè)策劃與數(shù)據(jù)分析、創(chuàng)意藝術(shù)與技術(shù)開(kāi)發(fā)的融合,累計(jì)客戶上千余家,服務(wù)滿意度達(dá)97%。幫助廣大客戶順利對(duì)接上互聯(lián)網(wǎng)浪潮,準(zhǔn)確優(yōu)選出符合自己需要的互聯(lián)網(wǎng)運(yùn)用,我們將一直專注成都品牌網(wǎng)站建設(shè)和互聯(lián)網(wǎng)程序開(kāi)發(fā),在前進(jìn)的路上,與客戶一起成長(zhǎng)!
Dim?a?As?Integer?=?Int(Rnd()?*?100)
If?a?Mod?2?=?0?Then
MsgBox(a??"是偶數(shù)")
Else
MsgBox(a??"是奇數(shù)")
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() '產(chǎn)生隨機(jī)數(shù)種子 以防止每次生成結(jié)果都一樣
Dim a(100) As Integer '聲明數(shù)組存放數(shù)據(jù) 用來(lái)保存隨機(jī)數(shù)結(jié)果
Dim max As Integer, min As Integer '聲明兩個(gè)變量存最大值和最小值
min = 1000 : max = 0 '設(shè)置初值
For i = 0 To 99 '循環(huán)100次
a(i) = Int(Rnd() * 1000 + 1) '用rnd生成一個(gè)隨機(jī)數(shù) 由于rnd范圍為0-1之間的小數(shù).所以*1000設(shè)置他的范圍為0到999之間 加1變成1到1000之間
If a(i) = max Then max = a(i) '如果當(dāng)前數(shù)值大于最大值的變量就保存
If a(i) = min Then min = a(i) '如果當(dāng)前數(shù)值小于最小值的變量就保存
Next
MsgBox("最大值為" max)
MsgBox("最小值為" min)
End Sub
'產(chǎn)生10個(gè)正整數(shù)
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是雙精度 有效數(shù)值位52位 表示成指數(shù)的形式 即指數(shù)11位 即表示成
所以180.89305用2進(jìn)制表示是10110100.1110010010011110111011001011111110110001010110110101
即
180.89305在double中存在的實(shí)際數(shù)值是
1.01101001110010010011110111011001011111110110001010110110101 *2^7
取小數(shù)點(diǎn)后 52位有效值后 等于10進(jìn)制的180.893049999999998
所及加最后變成了 1808930.99999999998
第一次當(dāng)然輸出近似值1808931
第二次int函數(shù)去掉了小數(shù)點(diǎn)后的數(shù)int就是只取整數(shù)的部位的不是四舍五入 所以少了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
判斷輸入是否是整數(shù),IsNumeric(tmpStr) 是判斷是否是數(shù)字,InStr(tmpStr, ".")是判斷是否有小數(shù)點(diǎn).
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