Private Sub Form_Load() Me.Hide Dim a As String Dim b As Integer Open App.Path & "/in.txt" For Input As #1 Open App.Path & "/out.txt" For Output As #2 a = 1 Input #1, x For i = 1 To x a = a * i Next
b = Len(a)
For i = b To 1 Step -1 c = Mid(a, i, 1) If c <> 0 Then Print #2, c Exit For End If 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, x ans = 1 For i = 1 To x ans = ans * i For j = Len(ans) To 1 Step -1 If Mid(ans, j, 1) <> 0 Then ans = Mid(ans, j, 1): Exit For Next Next Print #2, ans 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, x n = 1 For i = x To 1 Step -1 If n > 10000 Then n = n Mod 10000 n = n * i Do While n Mod 10 = 0 n = n \ 10 Loop Next i Print #2, Right(n, 1) Close #2 Close #1 End End Sub
Private Sub Form_Load()
回覆刪除Me.Hide
Dim a As String
Dim b As Integer
Open App.Path & "/in.txt" For Input As #1
Open App.Path & "/out.txt" For Output As #2
a = 1
Input #1, x
For i = 1 To x
a = a * i
Next
b = Len(a)
For i = b To 1 Step -1
c = Mid(a, i, 1)
If c <> 0 Then
Print #2, c
Exit For
End If
Next
Close
Close
End
End Sub
小冰程式有錯。
回覆刪除題目要求( 0 < N < 10000 )
1.但是你程式到1000就會溢位了
2.輸入100你會把 9.33262154439446E+157帶進去算
這樣就錯了
這題偏難,可以留以後再做
先把基礎打好再說
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
ans = 1
For i = 1 To x
ans = ans * i
For j = Len(ans) To 1 Step -1
If Mid(ans, j, 1) <> 0 Then ans = Mid(ans, j, 1): Exit For
Next
Next
Print #2, ans
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, x
n = 1
For i = x To 1 Step -1
If n > 10000 Then n = n Mod 10000
n = n * i
Do While n Mod 10 = 0
n = n \ 10
Loop
Next i
Print #2, Right(n, 1)
Close #2
Close #1
End
End Sub
小冰好,
回覆刪除程式正確,每次都取不是0的第1個數,是對的。
只是,你還是用字串的方式處理數字,小小危險。
哲好,
程式正確,用mod 和 整除 的方式取想要的數字是對的。
只是,你取的不是第1個不是0的數,當數字很大時,會不會有錯呢?
(在這題中是不會有錯,因為題目中已經限制了n的最大值)
暑假加油。
(在巴黎發呆中的熊掌)
作者已經移除這則留言。
回覆刪除