//求两个数的最大公约数
import java.io.IOException;
import java.util.Scanner;
public class p55 {
public static void main(String[] args) throws IOException
{
int a,b,k;
Scanner reader=new Scanner(System.in);
System.out.print("输入第一个整数:");
a=reader.nextInt();
System.out.print("输入第二个整数:");
b=reader.nextInt();
System.out.print("gcd("+a+","+b+")=");
do
{
k=a%b; //辗转相除求最大公约数
a=b;
b=k;
}while(k!=0);
System.out.println(a);
reader.close();
}
}
原文地址:https://www.cnblogs.com/duanqibo/p/11131957.html
时间: 2024-10-09 20:05:40