码迷,mamicode.com
首页 > 其他好文 > 详细

两个数的最大公约数

时间:2015-04-01 00:28:51      阅读:119      评论:0      收藏:0      [点我收藏+]

标签:c   算法   

问题:

          求两个数的最大公约数。

//最大公约数 
#include <stdio.h>
#include <stdlib.h>

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char *argv[]) {
	int m, n, b;
	int temp;
	scanf("%d%d", &m, &n);
	if(m<n)
	{
		temp = m;
		m = n;
		n = temp;
	}
	b = m % n;
	while(b!=0)//辗转相除法 
	{
		m = n;
		n = b;
		b = m % n;
	}
	printf("%d\n", n);
	return 0;
}
/*
56 72
8
*/


两个数的最大公约数

标签:c   算法   

原文地址:http://blog.csdn.net/orangeisnotapple/article/details/44787331

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!