编写一个VB程序,求一个最大的正整数N,使N!<3500。最后将N值保存到“C:valueN.dat”文件中。

来源:百度知道 编辑:UC知道 时间:2024/06/22 07:14:56

form 上放一个 多行、垂直滚动条的 文本框,一个按钮。
代码:

Private Sub Command1_Click()
Dim i As Integer, j As Integer, n As Integer
Dim prod As Integer
i = 1
prod = fun(i)
While prod < 3500
j = i
Text1.Text = Text1.Text + "N=" + CStr(j) + vbCrLf
Text1.Text = Text1.Text + CStr(j) + "!=" + CStr(fun(j)) + vbCrLf

i = i + 1
prod = fun(i)
Wend
End Sub

Private Function fun(n As Integer) As Integer
Dim i As Integer
Dim p As Integer
p = 1
For i = 1 To n
p = p * i
Next
fun = p
End Function

文件保存 自行解决!

Dim i As Integer
Dim result As Double

Private Sub Form_Load()
i = 1
result = 1
Do While (result < 3500)
result = result * i
i = i + 1
Loop
Open "C:\valueN.dat" For Append As #1
Print