您的位置:首页 > 其它

第一周:欧几里得求两个数的公约数

2014-03-08 20:52 316 查看
201111621319

#include <stdio>
using namespace std;
int x,y,z;


//求两个数的最大公约数

public class Testgcd {
 private int yueshu=1;
 private int gcd(int a,int b)
 {
  if(a%b==0)
   return b;
  else
   return gcd(b,a%b);
  
 }
 public int maincode(int a,int b)
 {
  if(a>b)
   yueshu=gcd(a,b);
  else
   yueshu=gcd(b,a);
  System.out.println(yueshu);
  return 0;
   
 }
 public static void main(String[] args) {
  Testgcd tgcd=new Testgcd();
  tgcd.maincode(1,2);
 }
}


结果 1
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: