내 코드 :감소 분수
Private Sub btnReduce_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnReduce.Click
Call Reduce()
End Sub
Function Reduce() As Single
Dim num As Integer = txtNum.Text
Dim deno As Integer = txtDeno.Text
For i = 1 To deno Step +1
If num Mod i = 0 Then
num = num/i
End If
If deno Mod i = 0 Then
deno = deno/i
End If
Next
lblOutputNum.Text = num
lblOutputDeno.Text = deno
End Function
I가 2/4을 입력하면이 1/2 나에게 제공합니다. 그러나 3/6을 입력하면 1/1이됩니다. 아무도 왜 이것을하는지 알 수 있습니까? 나는 이것을 알 수 없다. 할 수있는 사람 덕분에.
[비율을 감소] (http://stackoverflow.com/questions/24093302/visual-basic-reducing-fractions) 질문의 이전 버전에서 당신에게 주어진 독서 링크를 고려하시기 바랍니다. 나는 [GCD] (http://en.wikipedia.org/wiki/Greatest_common_divisor)를 계산 한 코드가 링크 된 [단순화 된 프랙 션]에서 제안 된 것처럼 보이지 않습니다. (http://stackoverflow.com/questions/5287514/how-to - 단순화 - 분수). –
그래,하지만 C#이야? – user3695840
GCD는 실제로 언어와 관련이 없습니다 .... [GCD] (http://simple.wikipedia.org/wiki/Gcd) - 해당 [Euclidean 알고리즘] (http://en.wikipedia.org/wiki/Euclidean_algorithm). –