哈哈哈
20道编程代码
1.1000以内的全部完数
Private Sub Command1_Click()
Dim n As Integer
Dim i As Integer
Dim s As Long
For n = 1 To 1000
s = 1
For i = 2 To n - 1
If n Mod i = 0 Then s = s + i
Next i
If s = n Then
Text1 = Text1 & n & " "
If k Mod 5 = 0 Then Text1 = Text1 & vbCrLf
End If
Next n
End Sub
Private Sub Command2_Click()vb所有代码
End
End Sub
2.百元买百鸡
Private Sub Command1_Click()
Dim i As Integer
Dim j As Integer
For i = 0 To 20
For j = 0 To 33
If 5 * i + 3 * j + (100 - i - j) * 1 / 3 = 100 Then
Text1 = Text1 & "买" & CStr(i) & "只公鸡" & CStr(j) & "只母鸡" & CStr(100 - i - j) & "只小鸡"
Text1 = Text1 & Chr(13) & Chr(10)
End If
Next j
Next i
End Sub
Private Sub Command2_Click()
End
End Sub
3.不靠边元素和
Private Sub Command1_Click()
Cls
Randomize
Dim a(5, 5) As Integer, s%
For i = 0 To 5
For j = 0 To 5
a(i, j) = Int(Rnd * 9)
Print a(i, j) & ",";
Sum = Sum + a(i, j)
Next j
Print
Next i
k = Sum
Sum = 0
For i = 0 To 5
Sum = Sum + a(i, 0) + a(i, 5) + a(0, i) + a(5, i) Next i
Sum = Sum - a(0, 0) - a(5, 0) - a(5, 5) - a(0, 5) Text1 = k - Sum
End Sub
Private Sub Command2_Click()
End
End Sub
4.递归函数求斐波拉契数列
Option Explicit
Private Sub Command1_Click()
Dim a1, a2, b As Integer
Dim i, n As Integer
n = InputBox("显示数列的前N项")
a1 = 1
For i = 1 To n
b = a1 + a2
Text1.SelText = b & " "
a1 = a2
a2 = b
Next i
End Sub
Private Sub Command2_Click() End
End Sub
5.各位数之和
Private Sub Command1_Click() Dim i As String
Dim j%
Dim s%
i = Text1
For j = 1 To Len(i)
st = Mid(i, j, 1)
s = s + Val(st)
Next j
Text2 = s
End Sub
Private Sub Command2_Click() End
End Sub
6.回文数
Private Sub Command1_Click() Dim x$, y$, c$, i%
x = Text1
For i = 1 To Len(x)
c = Mid(x, i, 1)
y = c + y
Next i
If y = x Then
Text2 = "x是回文数"
Else
Text2 = "x不是回文数"
End If
End Sub

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。