2012年4月30日 星期一

關係運算子


請設計一個程式,能判斷出兩個數值之間三種狀態的關係運算子:

(1)第一個數字大於第二個數字。
(2)第二個數字小於第一個數字。
(3)兩個數字一樣大。
第 4 頁/共 5 頁
輸入說明:每一列由二個數字所組成,為一組測試資料。每個數字與數字間的區隔為一個空白符號,當為0 0時表示結束。(請參照輸入範例)
輸入範例:in.txt
10 20
20 10
10 10
0 0
輸出說明:對於每組測試資料,輸出『>』、『<』、『=』,代表該二數字的關係。(請參照輸出範例)
輸出範例:out.txt



4 則留言:

  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
    Do
    Input #1, x, y
    If x <> 0 And y <> 0 Then
    If x < y Then Print #2, "<"
    If x > y Then Print #2, ">"
    If x = y Then Print #2, "="
    End If
    Loop Until x = 0 And y = 0
    Close
    Close
    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
    Do
    Input #1, x, y
    If (x = 0) And (y = 0) Then Exit Do
    If x > y Then Print #2, ">"
    If x < y Then Print #2, "<"
    If x = y Then Print #2, "="
    Loop
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  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
    Do
    Input #1, a, b
    If a = 0 And b = 0 Then Exit Do
    If a > b Then Print #2, ">"
    If a = b Then Print #2, "="
    If a < b Then Print #2, "<"
    Loop
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  4. Private Sub Form_Load()
    Me.Hide
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Do
    Input #1, r, n
    If Val(r) = 0 And Val(n) = 0 Then Exit Do
    If Val(r) = Val(n) Then Print #2, "="
    If Val(r) > Val(n) Then Print #2, ">"
    If Val(r) < Val(n) Then Print #2, "<"
    Loop
    Close #2
    Close #1
    End
    End Sub

    回覆刪除