posts - 70,comments - 80,trackbacks - 0
一、 找出 100 999 之间的整数中所有等于它每位数字立方和的数。
例如 153=13+53+33
答:o_t1.JPG
源代码:Private Sub Command1_Click()
Dim i As Integer, j As Integer
Dim m, n, k As Integer
j = 0
Text1.Text = ""
For  i = 100 To 999
    m = i \ 100
    n = (i \ 10) Mod 10
    k = i Mod 10
    If  i = m ^ 3 + n ^ 3 + k ^ 3  Then
        j = j + 1
        If  j Mod 6 = 0  Then
            Text1.Text = Text1.Text & vbCrLf
        Else
            Text1.Text = Text1.Text & i & "  "
        End If
    End If
Next i
End Sub


二、 求所以满足条件的四位数 abcd
 ①这四位数是 11 的倍数;
 
a,b c,d 是小于 10 的互不相同的自然数;
 
b+c=a
 
bc 是完全平方数(例如 b=2 c=5 ,则 bc=25 ,是完全平方数)。
答:o_t2.JPG
源代码:
Private Sub Command1_Click()
Dim i As Integer
Dim m, n, p, q As Integer
Text1.Text = ""
For i = 1000 To 9999
    If i Mod 11 = 0 Then
        m = i \ 1000
        n = (i \ 100) Mod 10
        p = (i \ 10) Mod 10
        q = i Mod 10
        If n + p = m And wqs(n * 10 + p) And diff(m, n, p, q) Then
            Text1.Text = Text1.Text & i & "  "
        End If
    End If
   
Next i
End Sub
Private Function wqs(x As Integer) As Boolean
If Int(Sqr(x)) ^ 2 = x Then
    wqs = True
Else
    wqs = False
End If
End Function
Private Function diff(ByVal x1 As Integer, ByVal x2 As Integer, ByVal x3 As Integer, ByVal x4 As Integer) As Boolean
If x1 <> x2 And x1 <> x3 And x1 <> x4 And x2 <> x3 And x2 <> x4 And x3 <> x4 Then
    diff = True
Else
    diff = False
End If
End Function


三、 已知四位数 3025 有一个特殊的性质:它的前两位数字 30 和后两位数字 25 的和是 55 ,而 55 的平方刚好等于该数( 552=3025 )。试编程输出具有这种性质的所有四位数。
答:o_t3.JPG
源代码:
Private Sub Command1_Click()
Dim i As Integer
Dim m, n As Integer
Text1.Text = ""
For i = 1000 To 9999
    m = i \ 100
    n = (i \ 10 Mod 10) * 10 + i Mod 10
    If (m + n) ^ 2 = i Then
        Text1.Text = Text1.Text & i & "  "
    End If
Next i
End Sub

四、编程找出四个互不相同的四个数,它们中任意两数之和为偶数,任意三数之和可以被3 整除,而且这四个数的和越小越好。(已知它们的和不大于50)。
答:o_t4.JPG
源代码:

Private Sub Command1_Click()
Dim m, n, p, q As Integer
For m = 1 To 12
    For n = m + 1 To 50
        For p = n + 1 To 50
            For q = p + 1 To 50
                If mul(m, n, p, q) And odd(m, n, p, q) And (m + n + p + q) < 50 Then
                     Text1.Text = Text1.Text & m & "  " & n & "  " & p & "  " & q & vbCrLf
                End If
            Next q
        Next p
    Next n
Next m
End Sub
Private Function odd(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer, ByVal r As Integer) As Boolean
If (x + y) Mod 2 = 0 And (x + z) Mod 2 = 0 And (x + r) Mod 2 = 0 And (y + z) Mod 2 = 0 And (y + r) Mod 2 = 0 And (z + r) Mod 2 = 0 Then
    odd = True
Else
    odd = False
End If
End Function
Private Function mul(ByVal x As Integer, ByVal y As Integer, ByVal z As Integer, ByVal r As Integer) As Boolean
If (x + y + z) Mod 3 = 0 And (x + y + r) Mod 3 = 0 And (y + z + r) Mod 3 = 0 Then
    mul = True
Else
    mul = False
End If
End Function
posted on 2006-09-27 09:39 木子李 阅读(570) 评论(4)  编辑 收藏 引用 网摘 所属分类: Visual Basic 课堂

FeedBack:
# re: Visual Basic 6.0编程竞赛题库一 参考答案(一)
2006-10-04 16:50 | 王伯伯
hai you ma   回复  更多评论
  
# re: Visual Basic 6.0编程竞赛题库一 参考答案(一)
2006-10-07 12:37 | 李翠霞
@王伯伯
最后几道题目我会在结束国庆节假期后做出并放在网页上,敬请关注!  回复  更多评论
  
# re: Visual Basic 6.0编程竞赛题库一 参考答案(一)
2008-05-26 14:21 | 阿龙
怎么不能保存啊   回复  更多评论
  
# re: Visual Basic 6.0编程竞赛题库一 参考答案(一)
2008-05-26 14:22 | 阿龙

郁闷啊,想保存。  回复  更多评论
  

只有注册用户登录后才能发表评论。