2012年11月20日 星期二

四捨五入


內容 : 
拿氣溫來說,攝氏15度和攝氏15.05度的差距對人來說差異實在不大,有了數學概數的觀念,我們可以透過四捨五入法來得到一個數字的估計值,進而方便統計。
現在請你將一些小數利用程式來四捨五入。
輸入說明 :
共計三個測資點,每個測資檔中有多行小數n(-1<=n<=1),至多小數點以下有100位數
輸出說明 :
請輸出四捨五入至小數點以下第二位的結果
範例輸入 :
1.00000 
0.5 
0.715 
0.1234567890 
-0.995

範例輸出 :
1.00 
0.50 
0.72 
0.12 
-1.00

4 則留言:

  1. Dim num As Double
    Dim subb As Boolean
    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, num
    If num < 0 Then subb = True
    num = ((Abs(num) * 100) + 0.5)
    num = Int(num) / 100
    If subb = False Then Print #2, Format(num, "0.00")
    If subb = True Then Print #2, "-" & Format(num, "0.00"): subb = False
    Loop Until EOF(1)
    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
    Do
    Input #1, n
    n = Format(n, "0.00")
    Print #2, n
    Loop Until EOF(1)
    Close #2
    Close #1
    End
    End Sub

    回覆刪除
  3. Private Sub Form_Load()
    Open App.Path & "\in.txt" For Input As #1
    Open App.Path & "\out.txt" For Output As #2
    Do Until EOF(1)
    Input #1, x
    x = Format(x, "0.00")
    Print #2, x
    Loop
    Close
    Close
    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 While Not EOF(1)
    Input #1, x
    x = Format(x, "0.00")
    Print #2, x
    Loop
    Close #2
    Close #1
    End
    End Sub

    回覆刪除