Created
April 4, 2014 03:16
-
-
Save peace2048/9967375 to your computer and use it in GitHub Desktop.
最大公約数を求める
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Module Module1 | |
Sub Main() | |
' 1000,2500,5000 の最大公約数を求める | |
Dim n = {1000, 2500, 5000}.Aggregate(AddressOf GDC) | |
Console.WriteLine(n) | |
Console.ReadLine() | |
End Sub | |
''' <summary> | |
''' 最大公約数を求める | |
''' </summary> | |
Function GDC(a As Integer, b As Integer) As Integer | |
Dim w As Integer | |
If a > b Then | |
w = b | |
b = a | |
a = w | |
End If | |
While b <> 0 | |
w = a Mod b | |
a = b | |
b = w | |
End While | |
Return a | |
End Function | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment