求此题VB的编码
面积为S的矩形(即在TEXT 里面输入的数字为矩形的面积S……为确切数字),各个边长均为自然数(不输入……)在LABEL中显示的可能有的几种形成可能……
eg:输入S=12,输出的答案为3(即1*12;2*6;3*4不记6*2,12*1,4*3……)
输入S=13,输出的答案为1
(请大家帮忙用BASIC 语言中的FOR NEXT编码解答哦!!!谢谢啦!!!)
问题补充:老师给的部分提示编码:
(1)int ( 13 / 4 ) = 3
(2)13 mod 4 = 1
(3)13 div 4 = 3
参考答案:'发生事件暂设为点击按钮Command1.
Private Sub Command1_Click()
Dim i As Integer, Area As Double, num As Integer, str1 As String
Area = Val(Text1.Text)
If Area < 1 Or Area - Int(Area) <> 0 Then
Msgbox "面积须不小于 1 且为整数,请重新输入!"
Exit Sub
End If
For i = 1 To Sqr(Area)
If i * Int(Area / i) = Area Then
num = num + 1
str1 = str1 & i & "*" & Int(Area / i) & "; "
End If
Next
Label1.Caption = "答案为" & num & ", 即 " & Left(str1, Len(str1) - 2)
End Sub