首页 > 其他 > 详细

求两个数的最大公约数

时间:2016-06-25 13:40:06      阅读:106      评论:0      收藏:0      [点我收藏+]

#include<stdio.h>
#include<math.h>
#define true 1
int MaxGYS(int m,int n)//求最大公约数
{
  int r;
  while(true)
  {
    r=m%n;
    if(r==0)
    {
      return n;
    }
    else
    {
      m=n;
      n=r;
    }
  }
}
int main()
{
  int m,n,max,t;
  printf("please input m and n:\n");
  scanf("%d%d",&m,&n);
  if(n>m)
  {
    t=n;
    n=m;
    m=t;
  }
  max=MaxGYS(m,n);
  printf("%d是最大公约数\n",max);
  return 0;
}

求两个数的最大公约数

原文:http://www.cnblogs.com/ncuhwxiong/p/5616169.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!