Created
January 3, 2015 10:20
-
-
Save takanakahiko/5269035de5966def90b5 to your computer and use it in GitHub Desktop.
2つの自然数の最小公約数を求めるプログラム(1.3)
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
public class CommonDivisor{ | |
public static void main(String[] args){ | |
System.out.println("\tx\ty\tr"); | |
int x = Integer.parseInt(args[0]); | |
int y = Integer.parseInt(args[1]); | |
int r = x % y; | |
System.out.println("\t"+x+"\t"+y+"\t"+r); | |
while(r!=0){ | |
x = y; | |
y = r; | |
r = x % y; | |
System.out.println("\t"+x+"\t"+y+"\t"+r); | |
} | |
System.out.println("最大公約数は"+y+"です"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment