A1.印出等第
Dim a As Single
Dim s As String
a = InputBox("輸入a=", "成績", 0)
Select Case a
Case Is >= 90
s = "優"
Case Is >= 80
s = "甲"
Case Is >= 70
s = "乙"
Case Is >= 60
s = "丙"
Case Else
s = "丁"
End Select
Me.TextBox1.Text = s
A2.求 2^2 + 4^2 +..... + 100^2 結果
Dim sum = 0
For i = 2 To 100 Step 2
sum += i ^ 2
Next
Me.TextBox2.Text = sum
A3.一元二次方程式
Dim a, b, c As Integer
Dim ans = ""
a = InputBox("輸入a=", "求解", 0)
b = InputBox("輸入b=", "求解", 0)
c = InputBox("輸入c=", "求解", 0)
Dim d As Single = (b ^ 2 - 4 * a * c)
If d > 0 Then
ans &= "有相異實根" & "X = " & (-1 * b + d ^ 0.5) / (2 * a) & " , " & (-1 * b - d ^ 0.5) / (2 * a)
ElseIf d = 0 Then
ans = "有重根 , " & "x = " & (-1 * b) / (2 * a)
Else
ans = "有相異虛根 , " & "此方程式不存在"
End If
Me.TextBox3.Text = ans
A5. 三角形
Dim a, b, c As Single
Dim ans As String = ""
a = InputBox("a =", "判斷是否能構成三角形?", 0)
b = InputBox("b =", "判斷是否能構成三角形?", 0)
c = InputBox("c =", "判斷是否能構成三角形?", 0)
If a + b > c And a + c > b And b + c > a Then
Dim s As Single = (a + b + c) / 2
ans = "三角形面積 = " & (s * (s - a) * (s - b) * (s - c)) ^ 0.5
Else
ans = "非三角形"
End If
Me.TextBox5.Text = ans
沒有留言:
張貼留言