給你一組數字,請寫一個程式計算出這組數字的平均值,四捨五入至小數第2 位。
輸入說明:
第一行的數字,代表有幾個問題要求解。第二行開始的每一行,為一個獨立的問題。每
一行的第一個整數為這個問題所屬數字的數目n,其範圍為[2, 100]間的整數。接下來的n 個
整數,分別代表這n 個數字的數值,數值範圍為[1, 100]間的整數。
輸出說明:
對輸入的每個問題,分別以一行輸出平均數,輸出的格式請四捨五入至小數第二位。
輸入範例:
2
5 2 4 6 8 10
3 52 30 61
輸出範例:
6.00
47.67
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, x
For i = 1 To x
ans = 0
Input #1, n
For y = 1 To n
Input #1, a
ans = ans + a
Next
Print #2, Format(ans / n, "##0.00")
Next
Close
Close
End
End Sub
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
For i = 1 To n
ans = 0
Input #1, x
For j = 1 To x
Input #1, c
ans = ans + c
Next j
Print #2, Format(ans / x, "##0.00")
Next i
Close #2
Close #1
End
End Sub
小冰、晟晟好,
回覆刪除程式正確。繼續向前。
Private Sub Form_Load()
回覆刪除Open App.Path & "\in.txt" For Input As 1
Open App.Path & "\out.txt" For Output As 2
Input #1, n
For i = 1 To n
Input #1, x
ans = 0
For j = 1 To x
Input #1, y
ans = ans + y
Next j
Print #2, Format(ans / x, "0.00")
Next i
Close #2
Close #1
End
End Sub
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
For i = 1 To n
Input #1, r
ans = 0
For j = 1 To r
Input #1, s
ans = ans + s
Next j
strA = Format(ans / r, "0.00")
Print #2, strA
Next i
Close #1
Close #2
End
End Sub
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
For i = 1 To a
ans = 0
Input #1, b
For j = 1 To b
Input #1, c
ans = ans + c
Next j
Print #2, Format(ans / b, "##0.00")
Next i
Close #2
Close #1
End
End Sub