17.一個(gè)程序?qū)崿F(xiàn)如下功能:在文本框text1中輸入一個(gè)數(shù),在文本框text2中輸入需要轉(zhuǎn)換的進(jìn)制(小于等于16),點(diǎn)擊轉(zhuǎn)換按鈕,在標(biāo)簽Label3輸出轉(zhuǎn)換后的十進(jìn)制數(shù),程序運(yùn)行界面如圖所示: (1)請(qǐng)?jiān)跈M線處填入合適的代碼 Private Sub Commandl Click Dim s As String,k As Integer (1)
k-Val(Text2Text Labl3.Caption=“對(duì)應(yīng)的十進(jìn)制數(shù):“+St(toD(s,k)) End Sub Function toD(s As String,k As Integer) As Integer Dim ans As Integer,x As Integer ans=o For i-I To Len(s) If Mid(s,i,1)>=“A“And Mid (s,i,1)<=“F”Then x=Asc(Mid(s,i,1)-Asc(A“)+10 x=Val(Mid(s,i,1)) End If (2)
18.哥德巴赫1742年給歐拉的信中提出了以下猜想:任一大于2的偶數(shù)都可寫成兩個(gè)質(zhì)數(shù)之和,是為著名的哥德巴赫猜想。下面VB程序用來驗(yàn)證4-10000的偶數(shù)分解。 請(qǐng)完善下列程序代碼: Function prime(x As Integer) As Boolean’此函數(shù)判斷x是否為質(zhì)數(shù) prime=True For i=2To Int(Sqr(x)) If
Then prime=False:Exit For Next i End Function Private Sub Command2_Click ( ?。?br />Dim a As Integer,b As Integer Dim n As Integer
For a=2To n\2 b=n-a If
Then List1.AddItem Str(a)+““+Str(b)+““+Str(n) End If Next End Sub