⑴ VB,迴文數,水鮮花數,怎麼寫
求100至999中的迴文數:
Dim a As Integer, b As Integer, c As Integer, n As Integer
n = 0
For a = 1 To 9
For b = 0 To 9
n = n + 1
If (n Mod 9) = 0 Then
Print a & b & a
Else: Print a & b & a,
End If
Next b
Next a
Print Chr(13) & Chr(13) & "100至999中迴文數的個數為" & n
從LZ的程序來看,似乎是想求10至999中的水仙花數。但水仙花數是指一個n(>=3)位數字的數,它等於每個數字的n次冪之和。所以不存在兩位數的水仙花數。
我就簡化為求三位數中的水仙花數。以下是我的程序:
Dim a As Integer, b As Integer, c As Integer, n As Integer
n = 0
For a = 1 To 9
For b = 0 To 9
For c = 0 To 9
If a * 100 + b * 10 + c = a ^ 3 + b ^ 3 + c ^ 3 Then
n = n + 1
If (n Mod 5) = 0 Then
Print a & b & c
Else: Print a & b & c,
End If
End If
Next c
Next b
Next a
Print Chr(13) & Chr(13) & "三位數中水仙花數個數為" & n
不知道這樣的答案符不符合你的要求呢?呵呵~~~
⑵ 求200-300的迴文數vb程序
PrivateSubCommand1_Click()
Fori=200To300
Ifi100=iMod10ThenPrinti;
Nexti
EndSub
⑶ 急 求 VB判斷迴文數的代碼
建一個Text1,Text2,Command1。
Text1,Text2的Multiline都設置為True。
代碼如下。
============
Private Sub Command1_Click()
Text2.Text = ""
Dim a, i As Integer, n, s As String
a = Split(Text1.Text, vbCrLf)
For Each n In a
s = s & n
If n = StrReverse(n) Then s = s & "★"
s = s & vbCrLf
Next
Text2.Text = s
End Sub
⑷ vb編程迴文數
你看我回答的記錄裡面有三個一行輸出 迴文數的···原理就是 隨機產生randomize int(rnd*9999)+1000 再判斷這個數是否是迴文數,stringrev=string 順序=倒序,再三個一行輸出···
⑸ VB判斷迴文數程序怎麼打
建一個Text1,Text2,Command1。
Text1,Text2的Multiline都設置為True。
代碼如下。
Private Sub Command1_Click()
Text2.Text = ""
Dim a, i As Integer, n, s As String
a = Split(Text1.Text, vbCrLf)
For Each n In a
s = s & n
If n = StrReverse(n) Then s = s & "★"
s = s & vbCrLf
Next
Text2.Text = s
End Sub
⑹ vb求迴文數
PrivateSubCommand1_Click()'迴文數
Fori=100To200
ge=iMod10
shi=i10Mod10
=i100
Ifge=Then
Printi,
geshu=geshu+1
IfgeshuMod9=0ThenPrint
EndIf
Nexti
Print"geshu=";geshu
EndSub
⑺ VB找迴文數
'畫兩個command按鈕和一個Listbox控制項
Private Sub Command1_Click()
Dim i As Integer
Dim a As String
Dim j As Long
For i = 11 To 10000
If CStr(i) = StrReverse(CStr(i)) Then
j = i ^ 2
If CStr(j) = StrReverse(CStr(j)) Then
List1.AddItem CStr(i) & "^2=" & CStr(j)
End If
End If
Next
End Sub
Private Sub Command2_Click()
End
End Sub
⑻ vb中什麼是迴文數
錯誤1:變數c沒有定義,無法確定是全局變數,還是局部變數
錯誤2:If Left(i, j) = Right(i, j) Then 這句有問題,應該用MID函數
錯誤3: 循環中有問題,即使前面若干次huiwen = False ,而最後一次huiwen = True ,也會被程序誤判斷為迴文數
問題4: Command1_Click中 i變數沒有必要定義,直接傳遞Text1.Text就可以了
問題5: Function huiwen(i As String) 後沒有定義類型
好的習慣1: 最好定義每一個變數,j變數沒有定義
好的習慣2: i,j,k 一般是循環變數,不要把它們做為參數傳遞
按照你的思路,修改如下:
Function huiwen(hw As String) As Boolean
Dim j As Integer
Dim c As Integer
c = Len(hw)
huiwen = True
For j = 1 To c / 2
If Mid(hw, j, 1) <> Mid(hw, c - j + 1, 1) Then
huiwen = False
Exit For
End If
Next
End Function
Private Sub Command1_Click()
If huiwen(Text1.Text) = True Then
MsgBox "迴文"
Else
MsgBox "非迴文"
End If
End Sub
⑼ VB 迴文數
private
sub
command1_click()
'第一問
dim
i
as
long
cls
for
i
=
1
to
1000
if
hws(i
+
2013)
then
print
i
next
i
end
sub
private
sub
command2_click()
'第二問
dim
i
as
long
cls
for
i
=
1
to
1000
if
hws(i
+
2013)
and
hws(i)
then
print
i
next
i
end
sub
private
function
hws(n
as
long)
as
boolean
'判斷迴文數的函數
if
strreverse(cstr(n))
=
cstr(n)
then
hws
=
true
end
function
strreverse()函數的作用是將字元串反轉,例如「abcd「反轉後為」dcba「。