Dim ans As Long, x As Long, tt As Long 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, tt ans = 0 For i = 1 To tt x = i Do If x Mod 5 = 0 Then ans = ans + 1 x = x \ 5 Else GoTo isN End If Loop Until x < 5 isN: Next i Print #2, ans Loop 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 Do Until EOF(1) Input #1, x k = 0 For i = 1 To x q = i Do If q Mod 5 = 0 Then k = k + 1: q = q / 5 Else Exit Do End If Loop Next i Print #2, k Loop Close #2 Close #1 End Sub BY 阿揚
Dim ans As Long, x As Long, tt As Long
回覆刪除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, tt
ans = 0
For i = 1 To tt
x = i
Do
If x Mod 5 = 0 Then
ans = ans + 1
x = x \ 5
Else
GoTo isN
End If
Loop Until x < 5
isN:
Next i
Print #2, ans
Loop
Close #2
Close #1
End
End Sub
輸入:
1
2
10
5
25
100
99999999
100000000
輸出:
0
0
2
1
6
24
24999991
24999999
(老師,後面的兩個輸入,在跑的時候會有點卡說0.0)
還發現了用excel做階層的乘法
到21就會出錯了說
BY 小白
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
k = 0
For i = 1 To x
q = i
Do
If q Mod 5 = 0 Then
k = k + 1: q = q / 5
Else
Exit Do
End If
Loop
Next i
Print #2, k
Loop
Close #2
Close #1
End Sub
BY 阿揚
小白、阿揚好,
回覆刪除1.兩個的程式都OK,都抓到重點,反正就是算幾個5為主。25,225,625...
2.小白的goto,不好,用阿揚的exit do。
3.小白說的excel的錯,可以用=mod(x,y)
我可以算出50階乘有幾個0,用excel。
4.小白的輸入資料,有進步。會利用差1的輸入,可以試著去判斷結果是不是可能正確。同樣的地方,100,99也可以,或是249,250之類的。