⑴ 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“。