2012年11月20日 星期二

三角形的判斷



內容 : 
給你一個三角形的邊長,請你判斷它是銳角 (acute)、直角 (right)、或是鈍角 (obtuse) 三角形。

輸入說明 :
輸入只有一行,含有三個由空白隔開的正整數 a, b, c (0 < a, b, c ≤ 46340),代表三角形的邊長。
輸出說明 :
依三角形的類別輸出「acute triangle」、「right triangle」、或「obtuse triangle」。

範例輸入 :
3 4 5
範例輸出 :
right triangle    

6 則留言:

  1. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, temp1, temp2, temp3
    If temp1 > Max Then Max = temp1: a = temp2: b = temp3
    If temp2 > Max Then Max = temp2: a = temp1: b = temp3
    If temp3 > Max Then Max = temp3: a = temp1: b = temp2
    If (Max ^ 2) = (a ^ 2) + (b ^ 2) Then Print #2, "right triangle"
    If (Max ^ 2) > (a ^ 2) + (b ^ 2) Then Print #2, "obtuse triangle"
    If (Max ^ 2) < (a ^ 2) + (b ^ 2) Then Print #2, "acute triangle"
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  2. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, a, b, c
    If a + b > c And a + c > b And b + c > a Then
    If (a ^ 2 + b ^ 2 = c ^ 2) Then Print #2, "right triangle"
    If (a ^ 2 + b ^ 2 < c ^ 2) Then Print #2, "acute triangle"
    If (a ^ 2 + b ^ 2 > c ^ 2) Then Print #2, "obtuse triangle"
    End If
    Close
    Close
    End
    End Sub

    回覆刪除
  3. Dim z(3)
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    For i = 1 To 3
    Input #1, z(i)
    Next
    For i = 1 To 3
    For j = 1 To 2
    If z(j) > z(j + 1) Then
    x = z(j)
    z(j) = z(j + 1)
    z(j + 1) = x
    End If
    Next
    Next
    a = z(1)
    b = z(2)
    c = z(3)
    If a + b > c And a + c > b And b + c > a Then
    If (a ^ 2 + b ^ 2 = c ^ 2) Then Print #2, "right triangle"
    If (a ^ 2 + b ^ 2 < c ^ 2) Then Print #2, "acute triangle"
    If (a ^ 2 + b ^ 2 > c ^ 2) Then Print #2, "obtuse triangle"
    End If
    Close
    Close
    End
    End Sub

    回覆刪除
  4. Bob,長邊平方 > 短邊平方和是銳角,< 則是鈍角。

    回覆刪除
  5. Dim n(3) As Integer
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, n(1), n(2), n(3)
    For i = 1 To 2
    For j = 2 To 3
    If n(i) < n(j) Then
    a = n(i)
    n(i) = n(j)
    n(j) = a
    End If
    Next
    Next
    If n(1) ^ 2 = n(2) ^ 2 + n(3) ^ 2 Then
    Print #2, "right triangle"
    ElseIf n(1) ^ 2 > n(2) ^ 2 + n(3) ^ 2 Then
    Print #2, "acute triangle"
    Else
    Print #2, "obtuse triangle"
    End If
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  6. Dim a, b, c, d As Integer
    Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Input #1, a, b, c
    a = Val(a): b = Val(b): c = Val(c)
    d = a ^ 2 + b ^ 2
    If d = c ^ 2 Then Print #2, "Right triangle"
    If d > c ^ 2 Then Print #2, "acute triangle"
    If d < c ^ 2 Then Print #2, "obtuse triangle"
    Close #2
    Close #1
    End
    End Sub

    回覆刪除