|
我刚入门EXCEL VBA编程,现在碰到个题目想请教大家:
1.求一组数,它除3余2,除5余3,除7余2,求满足上面要求的所有数[1,100]
2.求所有两位数,该数要满足:这个数的平方数的各个位数之和是原数的一半。如18*18=324, 3+2+4=9,9=18/2
3.然后再把这些数从小到大冒泡排列,要求在一个模块中编程
这是我编的3个单独的程序:
1.
Sub main()
Dim i As Integer
For i = 1 To 100
If i Mod 3 = 2 And i Mod 5 = 3 And i Mod 7 = 2 Then
Debug.Print i
End If
Next
End Sub
2.
Private Sub Form_Click()
Dim i As Integer
Dim j As Integer
Dim b(1 To 4) As Integer
Dim s As Integer
Dim k As Integer
For i = 10 To 99
j = i * i
b(1) = j \ 1000 Mod 10
b(2) = j \ 100 Mod 10
b(3) = j \ 10 Mod 10
b(4) = j Mod 10
s = 0
For k = 1 To 4
s = s + b(k)
Next k
If s * 2 = i Then
Debug.Print i
End If
Next
End Sub
3.
Option Explicit
Sub main()
Dim i As Integer
Dim j As Integer
Dim temp As Integer
Dim flag As Boolean
Dim a(1 To 7) As Integer
a(1) = 8
a(2) = 5
a(3) = 11
a(4) = 9
a(5) = 2
a(6) = 7
a(7) = 6
For i = 1 To 7
flag = False
For j = i + 1 To 7
If a(j) < a(i) Then
temp = a(i)
a(i) = a(j)
a(j) = temp
flag = True
End If
Next
If flag = False Then
Exit For
End If
Next
For i = 1 To 7
Debug.Print "a(" & i & ")=" & a(i)
Next
End Sub
以上是3个分开的程序,我的问题是如何把1,2里求出来的数做从小到大的排序,也就是说最后出来的结果必须是1,2里的数而且要从小到大排序,1,2里的数我编的可以求出,问题就是我不知道怎么把他们弄一起然后做排序
望高人指点,小弟感激不尽 |
|