vb循环结构设计的5个题目,好心人帮帮忙,明天要用!!急!!!!!!!

2024-12-29 18:10:29
推荐回答(2个)
回答1:

我会陆续把每一题的解答加上去的。

1.
如果617 716 与 716 617是不同的话就有6个,否则3个。
419、914
518、815
617、716
716、617
815、518
914、419

程序如下:
Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Integer, i As Integer
i = 0
For a = 0 To 9
For b = 0 To 9
For c = 0 To 9
If ((a * 100) + (b * 10) + c) + ((c * 100) + (b * 10) + a) = 1333 Then
Me.Print ((a * 100) + (b * 10) + c); ((c * 100) + (b * 10) + a)
i = i + 1
End If
Next c
Next b
Next a
MsgBox "共有 " & i & " 个三位数符合题意。"
End Sub

2.
f(n)max=9426875, n = 21, f(n)max的平方为 88865972265625

程序如下:
Private Sub Command2_Click()
Dim f1 As Single, f2 As Single, f3 As Single, fn As Single, n As Integer
Me.Cls
f1 = 1: f2 = 2: f3 = 3: n = 4
Do Until fn > 5000000
fn = 3 * f1 + 2 * f2 + f3
f1 = f2
f2 = f3
f3 = fn
n = n + 1
Loop
MsgBox "小于5000000的最大项为 " & fn & ",此时n=" & n & "。即 f(n)max=f(" & n & ")=" & fn & vbCrLf & "所以f(n)max的平方为 " & (fn ^ 2)
End Sub

回答2:

2