2016年11月13日 星期日
1028
'p17 輸入 A, B, C,求一元二次方程式 AXଶ + BX + C = 0 的解。 if
Dim A, B, C As Single
A = Me.TextBox2.Text
B = Me.TextBox3.Text
C = Me.TextBox4.Text
Dim ans As String = ""
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.TextBox1.Text = ans
'p17 輸入 A, B, C,求一元二次方程式 AXଶ + BX + C = 0 的解。 select
Dim A, B, C As Single
A = Me.TextBox7.Text
B = Me.TextBox6.Text
C = Me.TextBox5.Text
Dim ans As String = ""
Dim d As Single = (B ^ 2 - 4 * A * C)
Select Case d
Case Is > 0
ans = "有相異實根 , " & "x = " & (-1 * B + d ^ 0.5) / (2 * A) & " , " & (-1 * B - d ^ 0.5) / (2 * A)
Case Is = 0
ans = "有重根 , " & "x = " & (-1 * B) / (2 * A)
Case Else
ans = "有相異虛根 , " & "此方程式不存在"
End Select
Me.TextBox8.Text = ans
' 9x9
Dim ans = ""
For j = 1 To 9 ' 9列
For i = 1 To 9 '1...9
ans &= RSet(i * j, 4) '向右靠對齊字串
Next
ans &= vbNewLine ' 換行
Next
Me.TextBox9.Text = ans
' 9x9
Dim ans = ""
For j = 1 To 9 ' 9列
For i = 1 To 9 '1...9
ans &= j & "x" & i & "=" & RSet(i * j, 2) & " " '向右靠對齊字串
Next
ans &= vbNewLine ' 換行
Next
Me.TextBox10.Text = ans
' 9x9
Dim ans = ""
For j = 1 To 9 ' 9列
For i = 1 To j '1...9
ans &= RSet(i * j, 4) '向右靠對齊字串
Next
ans &= vbNewLine ' 換行
Next
Me.TextBox11.Text = ans
'p39. 【直角三角形列印:軟體設計丙級】利用廻圈控制指令,由外部讀入整數數字,列印從 1 開始直到該數字為止之直角三角形。
Dim n As Integer
Dim ans = ""
n = InputBox("n = ", "p39【直角三角形列印:軟體設計丙級】利用廻圈控制指令,由外部讀入整數數字,列印從 1 開始直到該數字為止之直角三角形。", 4)
For j = 1 To n
For i = 1 To j
ans &= i
Next
ans &= vbNewLine ' 換行
Next
Me.TextBox12.Text = ans
'p21.P22 輸入正整數 n,求 1 + 2 + ....+ n
Dim n As Integer
Dim sum = 0
n = InputBox("輸入正整數 n", "輸入正整數 n,求 1 + 2 + ....+ n")
For x = 1 To n
sum += x
Next
Me.TextBox13.Text = sum
'p25. 輸入正整數 n,求 1 ^ 2 + 2 ^ 2 +....n ^ 2
Dim n As Integer
Dim sum = 0
n = InputBox("輸入正整數 n", "輸入正整數 n,求 1 ^ 2 + 2 ^ 2 +....n ^ 2")
For i = 1 To n Step 1
sum += i ^ 2
Next
Me.TextBox14.Text = sum
'p24. 輸入正整數 n,求 1 + 3 + ⋯ + (2n + 1) 之結果。
Dim n As Integer
Dim sum = 0
n = InputBox("輸入正整數 n", "輸入正整數 n,求 1 + 3 + ⋯ + (2n + 1) 之結果。")
For i = 1 To 2 * n + 1 Step 2
sum += i
Next
Me.TextBox15.Text = sum
'p26. 輸入正整數 n,求1 ^ 2 - 2 ^ 2 + 3 ^ 2 .... n ^ 2 之結果。
Dim n As Integer
Dim sum = 0
n = InputBox("輸入正整數 n", "輸入正整數 n,求1 ^ 2 - 2 ^ 2 + 3 ^ 2 .... n ^ 2之結果。")
For i = 1 To n Step 1
sum += If(i Mod 2 = 0, -i ^ 2, i ^ 2)
Next
Me.TextBox16.Text = sum
'p27. 輸入正整數 n,求(1 - 1 / 2)(1 - 1 / 3)... (1 - 1 / n)之結果。
Dim n As Integer
Dim sum As Single = 0
n = InputBox("輸入正整數 n", "輸入正整數 n,求(1 - 1 / 2)(1 - 1 / 3)... (1 - 1 / n)之結果。")
sum = 1
For i = 2 To n Step 1
sum *= (1 - 1 / i)
Next
Me.TextBox17.Text = sum
'p28. 輸入正整數 n,求 = 1 - 1 / 2 + 1 / 3 - 1 / 4 .... 之結果。
Dim n As Integer
Dim sum As Single = 0
n = InputBox("輸入正整數 n", "輸入正整數 n,求 = 1 - 1 / 2 + 1 / 3 - 1 / 4 .... 之結果。")
sum = 1
For i = 2 To n Step 1
sum += If(i Mod 2 = 0, -1 / i, 1 / i)
Next
Me.TextBox18.Text = sum
訂閱:
張貼留言 (Atom)
沒有留言:
張貼留言