判断某正整数是一个回数的算法不知道怎么了
我是有点关于VB的一些问题想问你,因为才刚刚学写代码,所以有很多错误,下面有三题:1..(如121 25852 555 256652)
Private Sub Command1_Click()
Dim n As Integer, ch As String, i As Integer
ch = CStr(n)
i = 1
If i <= Len(ch) / 2 Then
b = Mid(ch, i, 1)
l = Mid(ch, Len(ch) - i + 1, 1)
i = i + 1
ElseIf b = l Then
Print "yes"
Else
Print "no"
End If
End Sub
这个我知道错了,但不知道什么地方不对劲.
2.编写程序,求出100之内的所有勾股数.(a^2+b^2=c^2 (a<>b))
Private Sub Command1_Click()
Dim a As Integer, b As Integer, c As Integer
a = Int(Rnd * 100) + 1
b = Int(Rnd * 100) + 1
If c ^ 2 = a ^ 2 + b ^ 2 And a <> b Then
Print c;
End If
End Sub
这个就是连反应都没有.
3.设计一个用二分法求方程x^3-x^4+4*x^2-1=0在区间[0,1]上的一个实根.
Option Explicit
Private Sub form_Click()
Dim a As Single, b As Single, c As Single, Esp As Single
Esp = InputBox("输入允许的误差值", "二分法")
a = 0#
b = 1#
Do
If (a ^ 3 - a ^ 4 + 4 * a ^ 2 - 1) * (b ^ 3 - b ^ 4 + 4 * b ^ 2 - 1) < 0 Then
c = (a + b) / 2
If (a ^ 3 - a ^ 4 + 4 * a ^ 2 - 1) * (c ^ 3 - c ^ 4 + 4 * c ^ 2 - 1) > 0 Then
a = c
Else
b = c
End If
End If
Loop Until Abs(b - c) <= Esp
Print c
End Sub
这个我就是什么都不知道了,每一次运行下来都是0.5