绝对值是“|”,可以直接显示,同理对数可用log(x)代替,根号和其他不支持显示。
10年积累的网站设计制作、成都网站建设经验,可以快速应对客户对网站的新想法和需求。提供各种问题对应的解决方案。让选择我们的客户得到更好、更有力的网络服务。我虽然不认识你,你也不认识我。但先做网站后付款的网站建设流程,更有西湖免费网站建设让你可以放心的选择与我们合作。
如果要显示数学式子,只能画吧。
计算时可用“^”求幂或求根,“/”表示除法和分数线,还有math类。
VB的运算顺序是:先乘除、后加减,有括号的先算括号内,有负号的先算负号。
请你比较一下这个运算中x和y的值:
Dim n As Single = 4
Dim x As Single
Dim y As Single
x = n + 1
x = x / n
x = x - 1
x = Math.Sqrt(x)
y = Math.Sqrt((n + 1) / n - 1)
这样就会发现,你的代码中括号的位置错了。
正确的应该是: Math.Sqrt((n + 1) / n - 1)
效果如图,代码如下:
Public Class Form1
'Circle类
Class Circle
Public Center As Point
Public Radius As Single
Public Sub New(c As Point, r As Single)
Center = c
Radius = r
End Sub
'绘制
Public Sub Draw(g As Graphics, pen As Pen)
g.DrawEllipse(pen, New RectangleF(Center.X - Radius, Center.Y - Radius, Radius * 2, Radius * 2))
End Sub
End Class
Private downPoint As Point '记录鼠标按下位置
Private circleList As New List(Of Circle) '已存放圆的列表
Private tmpCircle As Circle '临时圆(正在拖动)
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
DoubleBuffered = True '启用双缓冲绘图,避免闪烁
End Sub
Private Sub Form1_MouseDown(sender As Object, e As MouseEventArgs) Handles Me.MouseDown
downPoint = e.Location '记下位置
End Sub
Private Sub Form1_MouseMove(sender As Object, e As MouseEventArgs) Handles Me.MouseMove
If e.Button Windows.Forms.MouseButtons.Left Then Return '左键没按下则退出
Dim r As Single = Math.Sqrt((e.X - downPoint.X) ^ 2 + (e.Y - downPoint.Y) ^ 2) '算出半径
tmpCircle = New Circle(downPoint, r) '更新临时圆
Refresh() '先刷新掉之前绘制的临时圆
tmpCircle.Draw(Me.CreateGraphics, Pens.Black) '绘制临时圆
End Sub
Private Sub Form1_MouseUp(sender As Object, e As MouseEventArgs) Handles Me.MouseUp
circleList.Add(tmpCircle) '鼠标弹起,把临时圆加入圆列表
End Sub
Private Sub Form1_Paint(sender As Object, e As PaintEventArgs) Handles Me.Paint
For Each c As Circle In circleList
c.Draw(e.Graphics, Pens.Black) '绘制出每个圆
Next
End Sub
End Class
首先,要知道3次根号下 x ,就是x^(1/3),知道这个就可以写代码了: private sub form_load() x=inputbox("请输入要开三次方的数值") msgbox x^(1/3) end sub