admin 管理员组文章数量: 887021
2024年1月23日发(作者:ventimono官网)
哈哈哈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 nEnd SubPrivate Sub Command2_Click() EndEnd Sub2.百元买百鸡Private Sub Command1_Click()Dim i As IntegerDim j As IntegerFor 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 iEnd SubPrivate Sub Command2_Click() EndEnd Sub3.不靠边元素和Private Sub Command1_Click()ClsRandomizeDim 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 PrintNext ik = SumSum = 0For i = 0 To 5Sum = Sum + a(i, 0) + a(i, 5) + a(0, i) + a(5, i)Next iSum = Sum - a(0, 0) - a(5, 0) - a(5, 5) - a(0, 5)Text1 = k - SumEnd SubPrivate Sub Command2_Click() EndEnd Sub4.递归函数求斐波拉契数列Option ExplicitPrivate 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 t = b & " " a1 = a2 a2 = b Next iEnd SubPrivate Sub Command2_Click() EndEnd Sub5.各位数之和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 = sEnd SubPrivate Sub Command2_Click() EndEnd Sub6.回文数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 IfEnd Sub
版权声明:本文标题:VB常见20道编程代码 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1705983162h496634.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论