20.有如下Visual Basic程序: Private Sub Command1_Click ( ?。?br />Dim a As String,s As String Dim b As Integer,n As Integer a=Val(Text1.Text) s=““ Do While a>0 n=a Mod 2 s=Str(n)+s a=a\2 Loop Label1.Caption=s End Sub 運(yùn)行該程序,在文本框Text1中輸入9,單擊命令按鈕Command1,在標(biāo)簽Label1中顯示的是
21.小施想編寫(xiě)一個(gè)VB程序幫助弟弟練習(xí)最大公約數(shù)的計(jì)算,程序運(yùn)行界面如下圖所示。單擊“生成題目”按鈕Command1生成兩個(gè)兩位隨機(jī)正整數(shù),分別顯示在左邊的文本框Text1和中間的文本框Text2中。在右邊的文本框Text3中輸入結(jié)果并按回車(chē)鍵后,如果結(jié)果正確,將在該文本框右邊的標(biāo)簽Label3中顯示“√”,否則顯示“×”。請(qǐng)?jiān)诋?huà)線處填入合適的代碼。 Dim r As Integer‘用于存放最大公約數(shù) Private Sub Command1_Click ( ?。?br />Dim i As Integer Dim m As Integer Dim n As Integer Randomize (1)
n=Int ( Rnd*90)+10 Text1.Text=Str ( m ):Text2.Text=Str ( n ) Text3.Text=““:Label3.Caption=““ If m>n Then r=n Else r=m For i=r To 1 Step-1 If m Mod i=0 (2)
n Mod i=0 Then r=i Exit For End If Next i End Sub Private Sub Text3_KeyPress ( KeyAscii As Integer) If KeyAscii=13 Then If r=(3)
Then Label3.Caption=“√“Else Label3.Caption=“ד End If End Sub