VB程序设计题:设计窗体程序,输入x,y的值,计算下面数学式子的值,

2025-05-04 03:44:46
推荐回答(2个)
回答1:

vb6
Option Explicit
Const e = 2.718281828459
Const pi = 3.14159265358979
Const d2r = pi / 180#

Private Sub Form_Load()
    Dim x As Double
    Dim y As Double
    Dim c1 As Double
    Dim c2 As Double
    
    
    x = InputBox("输入x(deg):")
    y = InputBox("输入y(deg):")
    
    If x = 0# Or y <= 0# Then
        MsgBox ("输入数据超出公式计算范围!")
        Exit Sub
    End If
    
    
    c1 = 2 * Sin(90# * d2r) + 2# * x * e ^ y
    c1 = c1 / Sqr(Abs(x * y))
    c2 = x * x * x + e ^ -6 * Log(y)
    c2 = c2 * Sin(x * d2r) * Cos(y * d2r) / (x * x + y * y)
    c1 = c1 + c2
    If c1 < 0# Then
        MsgBox ("输入数据超出公式计算范围!")
        Exit Sub
    End If
    c1 = Sqr(c1)
    MsgBox ("计算结果为:" & c1)
    
    
    
End Sub

回答2:

Dim e As Double

Private Sub Command1_Click()
Dim x As Double
Dim y As Double
e = 2.718281828459
Dim r1 As Double
Dim r2 As Double
r1 = (x ^ 3 + (e ^ (-6)) * Log(y)) * ((Sin(x) * Sin(y)) / (x ^ 2 + y ^ 2))
r2 = (2 + 2 * x * (e ^ y)) / (Sqr(Abs(x * y)))
Dim r As Double
r = Sqr(r1 + r2)
End Sub